Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

234
228

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.

いろいろなサービスのAPIをcurlで叩くときの認証の扱い

Last updated at Posted at 2013-12-14

Qiita

URLのリクエストパラメタに?token=YOURTOKENのように付加してリクエストを送る.

Qiita APIドキュメント - Qiita:Developer

なお, ユーザ名+パスワードを/api/v1/authにpostすればtokenを取得できる.

GitHub

  • Basic認証, OAuth2トークン(ヘッダー or パラメータ)の3種類が使える.
$ curl -u "username" https://api.github.com
$ curl -H "Authorization: token OAUTH-TOKEN" https://api.github.com
$ curl https://api.github.com/?access_token=OAUTH-TOKEN

OAuth | GitHub API

webpay

  • curlに-uとして渡し, ベーシック認証を利用

curl APIドキュメント | WebPay: 開発者向けクレジットカード決済サービス

リクエスト例

$curl "https://api.webpay.jp/v1/charges" \ 
-u "test_secret_eHn4TTgsGguBcW764a2KA8Yd:"

curlコマンドは、-uオプションによってベーシック認証に必要なデータの受け渡しを行います。(APIキーの後にコロン":"を付けることで、パスワードを求められることを回避できます。)

NewRelics

  • ヘッダー

From the command line, you can use

curl -gH "x-api-key:REPLACE_WITH_YOUR_API_KEY" '<URL>'

Getting started with the New Relic REST API - New Relic Documentation

Box

  • ヘッダー
curl https://api.box.com/2.0/folders/FOLDER_ID \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Box Platform Developer Documentation

rackspace

まずcurlで"認証"

  • POSTのパラメータとしてauth: { "keyxxxx" : { ...
curl -k -X POST https://identity.api.rackspacecloud.com/v2.0/tokens -d 
'{ "auth":{ "RAX-KSKEY:apiKeyCredentials":{ "username":"<username>", "apiKey":"<apikey>" } } }' -H 
"Content-type: application/json"

8.2. Authentication with cURL - Cloud Files™ Developer Guide - API v1

  • その後はヘッダーに.
$ curl -X HEAD -D - \
       -H "X-Auth-Token: fc81aaa6-98a1-9ab0-94ba-aba9a89aa9ae" \
       https://storage.clouddrive.com/v1/CF_xer7_343

MongoHQ

  • 普通にパラメータとして
curl -X GET "https://api.mongohq.com/databases/vehicles/collections/rockets/documents?_apikey=12345&limit=5"

さくらクラウド

  • Basic/Digest認証

さくらのクラウドAPIはAPIキーとシークレットトークンを利用したBasic認証またはDigest認証を使用します。

さくらのクラウド API v1.1 ドキュメント

Ebook Glue

  • 普通にパラメータ
curl -o converted.epub \
    https://ebookglue.com/convert?token=your-api-key

Ebook Conversion API Documentation | Ebook Glue

Dropbox

  • ヘッダー
$ curl https://api.dropbox.com/1/account/info -H “Authorization: Bearer <access token>”

Using OAuth 2.0 with the Core API - Developer Blog - Dropbox

AccessTokeの取得までもcurlで進めることが出来る.

Crocodoc

  • パラメータ
$ curl "https://crocodoc.com/api/v2/document/upload" --data "token=${API_TOKEN}&url=http://web.crocodoc.com/files/test-simple.pdf"

API Reference | Crocodoc

234
228
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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
234
228

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?