TechNoob
TechNoob

Reputation: 41

How to generate an Access token without manual steps on facebook API

I am trying to make a simple Instagram post bot where I can provide a url of an image and a caption and it will post. I currently have a working python script that, will generate long life token from a fixed exchange token (generated manually at the graph api tool webpage) and will will post an image given a url.

The problem is after a while (Less than a day) the token expires and I have to manually generate another.

I can successfully generate an app access token but I don't believe you can use an app access token for posting content. Is there a way to automatically generate a user token? pref without using something like chromedriver to mimic a browser for the token generation

Any help is appreciated.

Upvotes: 0

Views: 2235

Answers (1)

jSpeciale
jSpeciale

Reputation: 47

First of all, I strongly recommend you to spend a few minutes reading the References on Access Tokens. From there you can better understand the different types of Access Tokens.

Moving on.. Make sure you are using the correct endpoint to get that Long Lived Access Token (If your token is taking only a day to expire, means you aren't).

Use the Long Lived Access Token path with the token you generated via Graph API Explorer:

curl -i -X GET "https://graph.facebook.com/{graph-api-version}/oauth/access_token?  
grant_type=fb_exchange_token&          
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={your-access-token}" 

App's Access Token does not give you access to Content Publishing. For that you need to use your User Token generated on the previous step. Make sure the User have all the Permissions needed: ads_management, business_management, instagram_basic, instagram_content_publish, pages_read_engagement.

Upvotes: 1

Related Questions