简体   繁体   中英

Generate Permanent Instagram Access Token

We have an Instagram client id and client secret, and already have gone through the documentation of generating access tokens which requires redirect url.

Note that we also have disabled the implicit OAuth flow.

Now we already have generated the access token using URL below (for authenticated user, it returns the access token appended in the response URL)

https://api.instagram.com/oauth/authorize/?client_id= {client_Id}&redirect_uri={redirect_url}&response_type=token&scope=public_content

Can this token be stored in the database / configuration files and re-used for any new Instagram API requests? eg https://api.instagram.com/v1/users/ {user_id}/media/recent/?access_token={reusable_access_token}

Based on the official documentation , we understand that the access token can become invalid at any point of time, we would like to know if there are any specific scenarios which leads to invalidation of the access token?

What would be the best way to generate token once and use it for each API request? We definitely do not want users to enter credentials manually to generate tokens.

Unfortunately at that point it's not possible:/ Instagram doesn't provide refreshing access token in the background.

User needs to login with their credentials, so you can obtain new access token. Some kind of workaround (not nice, but it's working) is to watch for error type OAuthAccessTokenException and notify the user via e-mail about such fact. He will have to login once more, so you can get fresh and working access token.

Also, please keep in mind that access tokens has a pretty long life span. It doesn't expire after a day or two, unless Instagram API has some issues (like just now OAuth - unable to exchange code to access token for some users). Otherwise it works really well.

However it would be super nice if Instagram could add to their API renewal option in the background for access tokens for users that autorised your app, but their token expired:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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