To post to pages you control, it’s sufficient to create an app and request the appropriate scopes (see below) when generating your access tokens.
If you want to post to pages you do not own (ie. on behalf of other businesses or people), you’ll need to pass additional approvals by Facebook to be granted advanced API permissions. This capability is out of scope for this project.
NB. Facebook removed support for posting to a user’s personal feed in 2018.
type=facebook;code=<SHORTCODE>;mode=page;page_id=<PAGE_ID>;page_token=<PAGE_TOKEN>
type=facebook;code=<SHORTCODE>;mode=user;user_token=<USER_TOKEN>
SHORTCODE
- a unique code to refer to the social network instance, this will appear in logsMODE
- set this to: Page
(case insensitive)Page
modePAGE_ID
- Id of the page to post toPAGE_TOKEN
- A page access token obtained through the process outlined in Facebook notesSome of the activities described below are implemented as scripts, found in this repository:
Script | Purpose |
---|---|
/scripts/fb-get-long-user-access-token.sh |
Exchange an app’s short-lived user access token for a long-lived one. |
/scripts/fb-get-all-page-access-tokens.sh |
Retrieve all page access tokens for the given user. |
Duration | User token | Page token |
---|---|---|
Short-lived | 1 hour | 1 hour |
Long-lived | 60 days | Indefinite |
NB. Although some tokens may last a long time, they can be invalidated if needs be.
User Token
public_profile
A popup dialog will prompt you to grant the public profile permission to the app.
See also: https://developers.facebook.com/docs/pages/access-tokens#get-a-page-access-token
You can exchange a short-lived token for a long lived one:
curl -i -X GET "https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&
client_id=APP-ID&
client_secret=APP-SECRET&
fb_exchange_token=SHORT-LIVED-USER-ACCESS-TOKEN"
pages_manage_posts
pages_read_engagement
pages_show_list
A popup dialog will prompt you to grant these page permissions to the app.
You can exchange your user access token for a page access token:
curl -i -X GET "https://graph.facebook.com/PAGE-ID?
fields=access_token&
access_token=USER-ACCESS-TOKEN"
curl -i -X GET "https://graph.facebook.com/USER-ID/accounts?
fields=name,access_token&
access_token=USER-ACCESS-TOKEN"