Help us understand the problem. What is going on with this article?

curl コマンドで Qiita API を試す方法

More than 1 year has passed since last update.

やること

  • curl コマンドで Qiita API を叩いてみる

Qiita API を実行するトークンを発行する

curl で Qiita API を叩いてみる

  • curl にオプションでヘッダーの設定が必要なので注意
$ curl -sSLH "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" https://qiita.com/api/v2/authenticated_user/
{"description":"","facebook_id":"","followees_count":44,"followers_count":2,"github_login_name":"itooww","id":"itooww","items_count":2,"linkedin_id":"","location":"","name":"","organization":"","permanent_id":79267,"profile_image_url":"https://qiita-image-store.s3.amazonaws.com/0/79267/profile-images/1473701386","twitter_screen_name":"itooww","website_url":"","image_monthly_upload_limit":104857600,"image_monthly_upload_remaining":104857600,"team_only":false}

レスポンスを見やすくする

$ curl -sSLH "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" https://qiita.com/api/v2/authenticated_user/ | jq -C .
{
  "description": "",
  "facebook_id": "",
  "followees_count": 44,
  "followers_count": 2,
  "github_login_name": "itooww",
  "id": "itooww",
  "items_count": 2,
  "linkedin_id": "",
  "location": "",
  "name": "",
  "organization": "",
  "permanent_id": 79267,
  "profile_image_url": "https://qiita-image-store.s3.amazonaws.com/0/79267/profile-images/1473701386",
  "twitter_screen_name": "itooww",
  "website_url": "",
  "image_monthly_upload_limit": 104857600,
  "image_monthly_upload_remaining": 104857600,
  "team_only": false
}

長いレスポンスを less で見る

$ curl -sSLH "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" https://qiita.com/api/v2/authenticated_user/items | jq -C . | less -R

検証環境

$ curl --version
curl 7.52.1 (i686-pc-cygwin) libcurl/7.52.1 OpenSSL/1.0.2j zlib/1.2.8 libidn2/0.11 libpsl/0.14.0 (+libidn2/0.11) libssh2/1.7.0 nghttp2/1.14.0
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: Debug IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy Metalink PSL

$ jq --version
jq-1.5

$ less --version
less 481 (POSIX regular expressions)
Copyright (C) 1984-2015  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less

Reference

所感

  • コマンドが長くなりすぎると入力とか面倒なので curl 以外で手軽な方法あれば知りたい・・・
    • API 試すアプリとかインストールするのは抵抗あるので cli で完結したいならスクリプト作れって話になりそう

EOF

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away