简体   繁体   English

从 Instagram 基本显示 API 获取长期访问令牌的问题

[英]Troubles Fetching a Long-lived Access Token from the Instagram Basic Display API

I am trying to work with the Instagram Basic Display API and I am getting stuck at obtaining a long-lived access token.我正在尝试使用 Instagram 基本显示 API,但在获取长期访问令牌时遇到了困难。 Hoping some of you folks can help me narrow down my issue.希望你们中的一些人可以帮助我缩小问题的范围。 Ive been making my way through Meta for Developers 'Get Started', currently stuck on Step 5: Exchange the Code for a Token:我一直在通过 Meta for Developers 'Get Started',目前停留在第 5 步:用代码交换令牌:

I've made it to the point where you can click to authenticate the Instagram test user, to which you get a redirected URI with an 'authorization code' appended to it.我已经做到了,您可以单击以对 Instagram 测试用户进行身份验证,您将获得一个重定向的 URI,并附有“授权代码”。 I then take that code and make a POST to https://api.instagram.com/oauth/access_token with the following params:然后我使用该代码并使用以下参数对https://api.instagram.com/oauth/access_token进行 POST:

  • client_id={insta-app-id} client_id={insta-app-id}

  • client_secret={insta-app-secret} client_secret={insta-app-secret}

  • grant_type=authorization_code grant_type=authorization_code

  • redirect_uri={redirect-uri} code={authorization-code} redirect_uri={redirect-uri} 代码={授权码}

I then get this response: { "error_type": "OAuthException", "code": 400, "error_message": "Missing required field client_id" }然后我得到这个响应: { "error_type": "OAuthException", "code": 400, "error_message": "Missing required field client_id" }

And if you find it helpful, this is more info about my approach:如果你觉得它有帮助,这是关于我的方法的更多信息:

  • the app is in not live and in 'developer mode',该应用程序未上线并处于“开发人员模式”,
  • I used the same Instagram App ID to 'Authenticate the Test User'我使用相同的 Instagram 应用 ID 来“验证测试用户”
  • not using the Facebook test app but instead tunneling my localhost through ngrok不使用 Facebook 测试应用程序,而是通过 ngrok 连接我的本地主机
  • The Valid OAuth Redirect URI ( Insta Basic Display – Client 0Auth Settings ), is exactly the same, as the Site URL ( Settings-Basic-Website ), this includes forward slashes.有效的 OAuth 重定向 URI(Insta 基本显示 - 客户端 0Auth 设置)与站点 URL(设置-基本-网站)完全相同,其中包括正斜杠。 Any help would be super appreciated!任何帮助将不胜感激!

Everything seems perfect.一切似乎都很完美。 Try an attempt on postman or web browser .尝试使用邮递员网络浏览器

Can you share the exact post you did?你能分享你做的确切帖子吗?

It sounds like a syntax error in the POST request.这听起来像是 POST 请求中的语法错误。

I opened a terminal and ran this exact CURL request:我打开了一个终端并运行了这个确切的 CURL 请求:

curl -X POST \
  https://api.instagram.com/oauth/access_token \
  -F client_id={app-id} \
  -F client_secret={app-secret} \
  -F grant_type=authorization_code \
  -F redirect_uri={redirect-uri} \
  -F code={code}

I got back json:我回来了 json:

{"id":"<user_id>", "username":"<username>"} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM