open-social-distributor

Facebook

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.

Facebook connection strings

type=facebook;code=<SHORTCODE>;mode=page;page_id=<PAGE_ID>;page_token=<PAGE_TOKEN>
type=facebook;code=<SHORTCODE>;mode=user;user_token=<USER_TOKEN>

Page mode

Tools

Scripts

Some 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.

Access tokens

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.

Get a user access token (explorer)

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

Get a long-lived user access token (CLI)

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"

Get a page access token (explorer)

A popup dialog will prompt you to grant these page permissions to the app.

Get a page access token (CLI)

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"

Get all access tokens for your pages

curl -i -X GET "https://graph.facebook.com/USER-ID/accounts?
  fields=name,access_token&
  access_token=USER-ACCESS-TOKEN"