LoginSignup
5
0

More than 5 years have passed since last update.

(Qiita API v2 活用) Qiita のユーザーを API 経由で取得する方法

Last updated at Posted at 2018-02-01

やりたいこと

Qiita に記事を書いているユーザーを簡単に調べたい。

ユーザー情報を確認するサンプルコード

curl "https://qiita.com/api/v2/users?page=1&per_page=100" \
  | jq 'map(select( .["items_count"] > 0))'

ポイントは、Qiita の投稿がある人で絞り込んでいるところ。

ユーザー名を指定してユーザー情報を確認するサンプルコード

curl "https://qiita.com/api/v2/users/kojiro-s" \
  | jq .

自分のユーザー情報の確認結果

{
  "description": null,
  "facebook_id": null,
  "followees_count": 0,
  "followers_count": 0,
  "github_login_name": null,
  "id": "kojiro-s",
  "items_count": 3,
  "linkedin_id": null,
  "location": null,
  "name": "",
  "organization": null,
  "permanent_id": 84349,
  "profile_image_url": "https://qiita-image-store.s3.amazonaws.com/0/84349/profile-images/1473703070",
  "twitter_screen_name": null,
  "website_url": null
}

ユーザー名を指定して Contribution を取得するサンプルコード

CONTRIBUTION_COUNT=$(curl --silent \
  "https://qiita.com/kojiro-s" \
  | xmllint --xpath '/html/body/div[2]/div/div/div[2]/div/div[2]/a[2]/span[1]' --html - \
  | sed -e 's|<span class="userActivityChart_statCount">\(.*\)</span>|\1|g')
echo "CONTRIBUTION_COUNT=[${CONTRIBUTION_COUNT}]"

ユーザー情報の取得 API でコントリビューション数が取得できなかったので抽出する方法を検討。

HTML のパースエラーがでるのは、ご愛嬌。

参考情報

この API はアカウントを作った順にユーザー情報が表示できる。

投稿数や貢献数で絞り込むことができない。

API 設計の参考になる。

HTML をパースしてコントリビューション数を取得されている。

5
0
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
5
0