8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

QiitaAPIのTOKENをかんたんに取得する

Posted at

QiitaAPIのTOKENを取得するのに、いちいちサーバーサイドを構築するのは面倒だったので、jQueryを使って1ファイルだけでTOKENを取得できるようにしてみました。

auth.html
<!DOCTYPE html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Qiita TOKEN</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
        <script type="text/javascript">
$(function() {
    $("#send").click(function() {
        $.ajax({
            type: "POST",
            url: "https://qiita.com/api/v1/auth/",
            async: true,
            cache: false,
            json: true,
            data: {url_name: $("#url_name").val(), password: $("#pass").val()},
            success: function(data) {
                alert(data.token);
            },
            error: function(xhr, status, error) {
                if (error === "Unauthorized") {
                    alert("パスワードが違います");
                } else {
                    alert(error);
                }
            }
        });
        return false;
    });
});
        </script>
    </head>
    <body>
        <form>
            <input id="url_name" pattern="^\w[\w\-]{1,30}\w$" placeholder="ユーザ名" type="text" />
            <input id="password" pattern="^\S{8,32}$" placeholder="パスワード" type="password" />
            <button id="send">送信</button>
        </form>
    </body>
</html>

このファイルをローカルに保存して実行するだけでOKです。

8
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?