首页 > 解决方案 > 如何使用 instagram api 在没有 refresh_token 的情况下刷新 access_token

问题描述

我正在为我的 instagram 客户端刷新我的 access_token,这样我的用户就不需要在每次访问令牌过期时都登录。有没有办法在没有 refresh_token 的情况下做到这一点(instagram api 响应不包含 refresh_token)。

您可以在此处查看 instagram 列出的步骤:https ://www.instagram.com/developer/authentication/

这是 instagram oauth api 的响应对象:

{“access_token”:“fb2e77d.47a0479900504cb3ab4a1f626d174d2d”,“用户”:{“id”:“1574083”,“用户名”:“snoopdogg”,“full_name”:“Snoop Dogg”,“profile_picture”:“...” } }

我希望响应中有一个“refresh_token”字段,以便稍后我们可以请求一个新的“access_token”。

标签: oauth-2.0instagram-api

解决方案


First, you'll need to get a long-lived access token using the regular access token (which is only valid for one hour):

curl -i -X GET "https://graph.instagram.com/access_token
  ?grant_type=ig_exchange_token
  &client_secret={instagram-app-secret}
  &access_token={short-lived-access-token}"

Then, you can refresh the long-lived token by requesting the GET /refresh_access_token endpoint using the long-lived token it-self:

curl -i -X GET "https://graph.instagram.com/refresh_access_token
  ?grant_type=ig_refresh_token
  &access_token={long-lived-access-token}"

Refreshing a long-lived token makes it valid for 60 days again.

You can check the Instagram documentation for more details.


推荐阅读