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.
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).
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)
https://graph.facebook.com/v2.10/me?access_token={access_token}
# access_token is your long term access token
# return your {user-id}
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}
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