35
34

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.

Qiita APIをJavaScriptから叩く

Posted at

QiitaAPIが公開されていたので,JavaScriptから使ってみるサンプル(jQuery使用)です.
target_nameで指定したユーザの投稿をすべてストックします.
JavaScriptはそんなに書かないので,怪しい部分は突っ込み大歓迎です.

qiita_test.js
var API_END_POINT = 'https://qiita.com/api/v1';

stockAllPostByUserName('target_name');

function stockAllPostByUserName(user_name) {
  var qiita_test = {};
  getToken(qiita_test);
  
  $.getJSON(API_END_POINT + '/users/' + user_name + '/items', null,
      function(response) {
        response.forEach(
            function(element) {
              stockItem(element.uuid, qiita_test.token);
            });
      });
}

function getToken(namespace) {
  $.post(API_END_POINT + '/auth',
      {url_name:'name',
       password:'password'},
      function(data){
         namespace.token = data.token;
      });
}

function stockItem(uuid, token) {
  $.ajax({url: API_END_POINT + '/items/' + uuid + '/stock',
         data: {token: token},
      success: function(response) {
                   console.log(response);
               },
         type: 'PUT'});
}
35
34
2

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
35
34

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?