LoginSignup
2
0

More than 5 years have passed since last update.

Instagram API を使ってみた

Posted at

Instagram APIを使うまでの初期設定を行ってみた。

Instagram APIは、今年の初めにAPIが変更になり、
自分の投稿しか取得できなくなったようです。
他のユーザ情報を取得するためには、
承認をしてもらう必要があるようです。

※ 2017年6月時点の情報なので、変わっていたら最新のやり方で実施ください。

以下のInstagram 管理画面から、「Register a New Client」 ボタンから
API利用設定を行う

https://www.instagram.com/developer/clients/manage/

AccessToken を取得

AccessToken を発行する際に設定する CODE を取得する
下記URLにブラウザからアクセスをする

https://api.instagram.com/oauth/authorize/?client_id=[CLIENT ID]&redirect_uri=[REDIRECT URI]&response_type=code

こんなURLにリダイレクトされるので、CODE 部分をコピー

http://localhost:8000/instgram/webhook?code=[CODE]

CODE などの必要なパラメータをセットして、AccessToken取得コマンドを実行する

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

結果はこんな感じで帰ってくるので、access_token が取れました。

{"access_token": "<!!!ここ!!!>", "user": {"id": "0000000", "username": "nonochichi", "profile_picture": "https://scontent.cdninstagram.com/xxxx/xxxxxx.jpg", "full_name": "Nonoich 123", "bio": "", "website": ""}}
2
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
2
0