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

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

More than 3 years have passed since last update.

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}}
Why not register and get more from Qiita?
  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
No 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
ユーザーは見つかりませんでした