8
10

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をNode.jsから触ってみる

Posted at

@mizchiさんの記事を元に触ってみました。

アクセストークンの取得

ここから取得します。

個人用アクセストークン > 新しいトークンを発行する

とりあえず色々試したいのでスコープは全てチェックしました。

発行される文字列をコピーしておきます。二度と表示されないので注意しましょう。

インストール

$ npm i qiita-js

関係ないけど
【エラー】Refusing to install as a dependency of itselfにひっかかりました汗

サンプルコードを書いてみる

index.js
// require in commonjs env
var Qiita = require('qiita-js');

// set your token
Qiita.setToken('<your token>');

// fetch resources!
Qiita.Resources.User.get_user('n0bisuke').then(function(user){
    console.log(user);
});

実行してみる。

$ node index.js

{ description: '@のびすけです。\r\n\r\nhttp://liginc.co.jp/author/nobisuke\r\nhttps://www.wantedly.com/users/49472\r\nhttp://offsidenow.phpapps.jp/',
  facebook_id: 'sugawara.ryousuke',
  followers_count: 69,
  followees_count: 23,
  github_login_name: 'n0bisuke',
  id: 'n0bisuke',
  items_count: 103,
  linkedin_id: '',
  location: '岩手 <-> 上野',
  name: 'Sugawara Ryousuke',
  organization: 'http://liginc.co.jp',
  profile_image_url: 'https://gravatar.com/avatar/dae1d4cc4599a65a5da6e1a1f9d96f05?d=https%3A%2F%2Fidenticons.github.com%2F9a034197db94d3fa733e5079c6eb313a.png&r=x',
  twitter_screen_name: 'n0bisuke',
  website_url: 'http://liginc.co.jp/member/member_detail?user=nobisuke' }

指定したユーザーの情報を取得できました。

思った以上に簡単ですね!

もっと色々と試してみたいのでAPIドキュメントQiita-jsのソースコードを眺めてみたいと思います。

8
10
0

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
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?