leadership-connections

Group project for Leadership

MPL-2.0 License

Stars
0

Leadership Connections

Generating FB Token

To be able to post pictures to the facebook page, we need a page access token. A page access token can be generated by first getting a user access token with page post permissions and then exchanging that for a page access token as detailed here. This a problem with this flow in that the page access token expires in an hour and so does the user access token, so an admin would have to reauth the app on an hourly basis.

This can be solved by exchanging a "long-lived" user access token for a page access token. Long lived page access tokens have no expiration. ref

So finally the steps:

  1. Go to Facebook Graph Explorer and obtain a normal user access token.
  • Make sure to change the appliction to "UGBA Connections"
  • Required permissions: publish_actions, publish_pages, manage_pages, pages_show_list
  1. Hop over to the terminal and run this command after setting the correct env vars
export LONG_AT=$(http --body "https://graph.facebook.com/v2.11/oauth/access_token?grant_type=fb_exchange_token&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&fb_exchange_token=$USER_AT" | jq --raw-output ".access_token")
  1. Exchange the long lived user token for a page access token
export FB_TOKEN=$(http --body "https://graph.facebook.com/v2.11/ugba155connections?fields=access_token&access_token=$LONG_AT" | jq --raw-output ".access_token")
  1. Store the page access token in config/secret/development.json for development or in the FB_TOKEN environment variable for production.