8
12

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.

Instagram の API の使い方

Last updated at Posted at 2018-01-26

Instagram に投稿した自分の写真のURL を、API を使って取り出すまでの方法です。

参考にしたページ
Instagram APIを使ってWebページに表示する

1) まずは、Client ID を取得します。同時に、Client Secret も取得します。
Instagram にログインしての作業になります。

instagram_jan2501.png

2) 次に code を取得します。
  Client ID と 登録の時に入力した Redirect URL が必要です。

  そして、ブラウザーで、次にアクセスします。
https://api.instagram.com/oauth/authorize/?client_id=CLIENT-IDredirect_uri=REDIRECT-URI&response_type=code

何かを間違えると、次のようになります。
instagram_jan2502.png

うまくいくと、REDIRECT_URL にとび、アドレスバーにコードが示されます。

3) 次にそのコードを使って、access_token を取ります。
  CLIENT_ID
  CLIENT_SECRET
  AUTHORIZATION_REDIRECT_URI
  CODE
  を自分のものと書き換えて下さい。
  CODE は、一度使うと無効になります。

#
CLIENT_ID=b1117b3a157b151115dacc67c351d17a
CLIENT_SECRET=a61111cb71af1a16b716d1ea5381811c
REDIRECT_URI=https://ekzemplaro.org
CODE=1313111aed351113b1db131d17111816
#
curl -F 'client_id='$CLIENT_ID \
    -F 'client_secret='$CLIENT_SECRET \
    -F 'grant_type=authorization_code' \
    -F 'redirect_uri='$REDIRECT_URI \
    -F 'code='$CODE \
	https://api.instagram.com/oauth/access_token > token.json
#

アクセストークンの表示

jq . token.json

4) 次にこのアクセストークンを使って、自分の投稿した画像の URL を取得します。

ブラウザーで、次のアドレスにアクセスすれば、JSON が表示されます。

https://api.instagram.com/v1/users/self/media/recent?access_token=取得したアクセストークン

instagram_jun0101.png

8
12
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
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?