🌊

Instagram API のアクセストークン取得手順

2025/01/29に公開

取得手順

下ごしらえ

  1. Facebookでページ作成
  2. instagramをプロアカウントにする
  3. ページをリンク

トークンを取得していく

  1. https://developers.facebook.com/apps/

  2. facebook ログイン

  3. meta for Developers アカウント作成

  4. 新規アプリを作成

  5. 「その他」を選択

  6. Instagram API を追加

  7. 「アプリの設定」の「ベーシック」を確認

  8. 「アプリID」と「app secret」をひかえる

  9. 「グラフAPIエクスプローラ」を起動

  10. 「ページアクセストークンの取得」を選択

  11. 「現在のページにのみオプトイン」を選んで、作成したページを選択

  12. パーミッション追加

    • pages_show_list
    • business_management
    • pages_read_engagement
    • instagram_basic
    • instagram_content_publish
    • instagram_manage_comments
    • instagram_manage_messages
  13. 「Generate Access Token」を選択して「アクセストークンA」を生成

  14. 下記のURLにて「アクセストークンB」を取得

    https://graph.facebook.com/v21.0/oauth/access_token?grant_type=fb_exchange_token&client_id=【アプリID】&client_secret=【app_secret】&fb_exchange_token=【アクセストークンA】
    
  15. 下記のURLにて「id」を取得

    https://graph.facebook.com/v21.0/me?access_token=【アクセストークンB】
    
  16. 下記のURLにて「アクセストークンC」を取得

    https://graph.facebook.com/v21.0/【ID】/accounts?access_token=【アクセストークンB】
    
  17. アクセストークンデバッガー」を起動

  18. 「アクセストークンC」でデバッグを選択して「ページID」を取得する

  19. 下記のURLで「Instagram ID」を取得

    https://graph.facebook.com/【アクセストークンデバッガーで確認できるページID】?fields=instagram_business_account&access_token=【トークンC】
    
  20. 下記のURLでJSONで投稿を取得できたら成功!

    https://graph.facebook.com/v21.0/{インスタグラムID}?access_token={アクセストークンC}&fields=media{like_count,media_url}
    

Discussion