Skip to content

Instantly share code, notes, and snippets.

@msramalho
Last active November 7, 2024 09:18
Show Gist options
  • Save msramalho/4fc4bbc2f7ca58e0f6dc4d6de6215dc0 to your computer and use it in GitHub Desktop.
Save msramalho/4fc4bbc2f7ca58e0f6dc4d6de6215dc0 to your computer and use it in GitHub Desktop.
How to get a Facebook long term (non-expiring) access token for a Page

0 - Open the token validator

Go to https://developers.facebook.com/tools/debug/accesstoken/ and use this page to test your tokens at each step, namely looking at their expiry date.

1 - Get a short-lived token

Go to developers.facebook.com and generate a User token with the permissions required.

To post to pages you need pages_show_list, pages_read_engagement, pages_manage_posts, public_profile.

This is {your-access-token}, the short live access token (1h).

2 - Get a long-term token from that (2 months)

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}"

# {graph-api-version} >= v10.0
# {app-id} = name of the app in https://developers.facebook.com/tools/explorer
# {app-secret} = secret from the app page > settings > basic > App Secret
# {your-access-token} = the User token from an account with admin permission for the facebook page

# returns your {long-lived-user-access-token} as access_token (2 months)

3 - Get your user id

https://graph.facebook.com/v2.10/me?access_token={access_token}

# access_token is your long term access token

# return your {user-id} 

4 - Get a non-expiring token

Take the token from the 2nd step and pass it as {long-lived-user-access-token}:

curl -i -X GET "https://graph.facebook.com/{graph-api-version}/{user-id}/accounts?access_token={long-lived-user-access-token}"

# {graph-api-version} >= v10.0
# {user-id} = id of the user (not of the app) from step 3
# {long-lived-user-access-token} = token from step 2

# returns a final data array with {access_token}
@rat1Na
Copy link

rat1Na commented Mar 7, 2024

Perhaps you should try it.

I managed to obtain a long-term token using the Facebook Lite + App Cloner APK
and until now, it's still working well...

Check out the tutorial video here => https://youtu.be/zcQ_YW8IktU

@howardfernandez
Copy link

Thanks for sharing this @msramalho ...very helpful!

@janez33
Copy link

janez33 commented May 9, 2024

I've not used it to look into those @janez33 but welcome any insight you may find!

Basically this video explains THE BEST and EASIEST WAY how can you get LONG LIVED token to access read_insights, ads_read and ads_management permissions :)
https://youtu.be/22u1cMLxylU

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment