How to Get Access Token from Instagram API

How to get access token from Instagram API

I found the solution to my own question here Impossible to get an access_token for Instagram Basic Display API

When using Postman for Instagram's API, you should fill out the info required under the POST request's Body, NOT the Parameters. And when in the body, just select x-www-form-irlencoded

Why can't I generate user token in Instagram API?

Facebook token generator seems to be broken, but you can generate your own long-lived access token following OAuth2 workflow (replace {} placeholders with your own values):

  1. In your browser, go to:
https://api.instagram.com/oauth/authorize?client_id={your-client-id}&client_secret={your-client-secret}&redirect_uri={a-valid-redirect-url}&scope=user_profile,user_media&response_type=code

  1. Login to your Instagram account and accept your application to access your data
  2. You should be redirected to {a-valid-redirect-url}?code=xxxxx#_ then copy to {code} query string value without the #_ at the end
  3. Use Postman to execute a POST request to https://api.instagram.com/oauth/access_token with x-www-form-urlencoded params
    • client_id: {your-client-id}
    • client_secret: {your-client-secret}
    • grant_type: authorization_code
    • redirect_uri: {a-valid-redirect-url}
    • code: {the code you extracted from query string}
  4. You should get a short-lived access-token response such as:
{
"access_token": "IGQVxxxxxxxxxx…",
"user_id": xxxxxxxxxx
}

  1. Exchange your short-lived access-token with a long-lived one: use Postman to execute a GET request to https://graph.instagram.com/access_token with query params:
    • client_id: {your-client-id}
    • client_secret: {your-client-secret}
    • grant_type: ig_exchange_token
    • access_token: {the short-lived access_token}
  2. You should get a long-lived access-token response such as:
{
"access_token": "IGQxxxxx…",
"token_type": "bearer",
"expires_in": 5169852
}

Generate non-expiring token for Facebook Graph API to publish on Instagram Business Account via Google Apps Script

I'm going to do a complete and definitive step-by-step to solve this problem in relation to posting photos on Instagram with access tokens from the Facebook Graph API.

Assuming that you already have an application created here:

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

With this products mark:

Sample Image

and linked to your account, access this page:

https://business.facebook.com/settings/system-users/

There, you will add a new System User but note that there is a very important detail, add it as Administrator Access!

After that, you MUST access the Applications tab on the left menu, choose your already created application and click Add People.

Select the Admin User you created and check all the existing boxes, which are:

Develop Application

see insights

Test Application

Manage Application

After registering this user with these accesses, go back to the System Users page, click on Generate new token and check all the necessary scopes that are even at the beginning of my question.

As I already want to prevent future necessary scopes, I marked them all. When debugging the token now here it is, freed forever and with all necessary scopes:

Sample Image

Instagram API, fetching instagram images with client credentials instead of users access tokens

Using OAuth with the access tokens is the only way to pull content from Instagram. Instagram doesn't have a public API - if there were no authorization it would be a public API.

What you need is a back-end service. Since you're only getting your own data, generate the access tokens and store them server side - a one time event. Create an endpoint to get the last 5 posts and server-side make the Instagram API call with the access tokens. The front-end will call the your new endpoint and display the posts.

Another option is a paid social media aggregator.



Related Topics



Leave a reply



Submit