instagram api 事始め access_tokenを取得する


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

1-1.ログイン

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

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


「Register a New Client」をクリックして新規作成しますー

 

1-3.必要情報を入力

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

 

1-4.アプリ完成!


それぞれの値をメモっておく。

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.認証する


「Authorize」をクリック!

 

2-3.codeを取得

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"
    }
}


※例:iTermにて

 
以上
 

自分の写真情報を取得

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

 

参考

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