LoginSignup
105
104

More than 5 years have passed since last update.

instagram api 事始め access_tokenを取得する

Posted at

1.アプリケーション登録

1-1.ログイン

https://instagram.com/accounts/login/
よりログインして以下のdeveloperにアクセス

1-2.アプリケーションの新規作成

スクリーンショット_2014_10_24_13_07.png
「Register a New Client」をクリックして新規作成しますー

 

1-3.必要情報を入力

スクリーンショット 2014-10-24 13.09.18.png

  • Applictaiton Nameは、アプリケーションの名前
  • Dscriptionは、説明などを入力
  • Websiteは、サイトのURLを入力(適当でもOK)
  • OAuth redirect_uriは、アクセストークンを取得する際にリダイレクトされるURL(適当でもOK)
  • Disable implicit OAuth は、チェック入れたまま
  • Enforce signed header は、チェックしないまま

 

1-4.アプリ完成!

スクリーンショット_2014_10_24_13_09.png
それぞれの値をメモっておく。

2. アクセストークンを取得する

2-1.authorization URLたたく

https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code
  • CLIENT-ID、REDIRECT-URIに先ほどメモった値を入力 ブラウザのURLに入力してアクセスする。

 

2-2.認証する

スクリーンショット 2014-10-24 13.11.41.png
「Authorize」をクリック!

 

2-3.codeを取得

スクリーンショット_2014_10_24_13_12.png

URLにcodeが入っているのでコピーする

例:
http://instagramtest.com/instagram/?code=68eeee1dffd8425aba1583c45ac22238
※ダミーです

 

2-4.access_tokenを取得

curl \-F 'client_id=CLIENT-ID' \
    -F 'client_secret=CLIENT-SECRET' \
    -F 'grant_type=authorization_code' \
    -F 'redirect_uri=YOUR-REDIRECT-URI' \
    -F 'code=CODE' \https://api.instagram.com/oauth/access_token
  • CLIENT-ID、CLIENT-SECRET、YOUR-REDIRECT-URIにメモったのを入力。CODEは2-3でコピったやつ。

以下みたいのが取得できます!

{
    "access_token": "fb2e77d.47a0479900504cb3ab4a1f626d174d2d",
    "user": {
        "id": "1574083",
        "username": "snoopdogg",
        "full_name": "Snoop Dogg",
        "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg"
    }
}

スクリーンショット_2014_10_24_13_39.png
※例:iTermにて

 
以上
 

自分の写真情報を取得

https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS-TOKEN

 

参考

• Instagram Developer Documentation
http://instagram.com/developer/authentication/

105
104
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
105
104