LoginSignup
4
5

More than 5 years have passed since last update.

Instagramのアクセストークンの取得方法

Posted at

Instagramのクロールを実施しようとAPI登録したんだけど、アクセストークンを取得できず詰まったので確認方法をメモしておく。

状況

以下URLに沿って、アクセストークンを取得しようとしたところエラーでアクセストークンが取得できない。
http://d.hatena.ne.jp/tksthdnr/20110922/1316717437

ターミナルで実行したコマンド

curl \                  
-F 'client_id=[Client ID]' \                    
-F 'client_secret=[Client Secret]' \                    
-F 'grant_type=authorization_code' \                    
-F 'redirect_uri=[Valid redirect URIs]' \                   
-F 'code=[code]' \                  
https://api.instagram.com/oauth/access_token                    

エラーMSG

{"error_message": "Matching code was not found or was already used.", "error_type": "OAuthException", "code": 400}
"Matching code was not found or was already used.

回避方法

参考:http://fujiyamaworks.blogspot.jp/2012/08/instagram-api-access-token.html

1.Security > Disable implicit Oauthのチェックを外す
image

2.以下URLにClient IDとValid redirect URIsを設定

https://instagram.com/oauth/authorize/?client_id=[Client ID]&redirect_uri=[Valid redirect URIs]&response_type=token&scope=public_content

3.「#access_token=」以下の値がアクセストークンとなる
image

URLには&scope=public_contentも付与しておく。
つけないとhttps://api.instagram.com/v1/tags/[Tag名]/media/recent/?access_token=[acessToken]でタグがついているものを取得しようとしたときに以下エラーとなる。

{"meta": {"error_type": "OAuthPermissionsException", "error_message": "This request requires scope=public_content, but this access token is not authorized with this scope. The user must re-authorize your application with scope=public_content to be granted this permissions.", "code": 400}}
4
5
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
4
5