skip to Main Content

I am hitting a wall while developing seamless integration of a Facebook page with my bot.

Essentially I want to achieve same integration than Chatfuel or Manychat have, where being logged in with your Facebook account lets you to just choose what page you are connecting to them and you are good to go.

The problem I am facing is generating the proper token in order to bind the selected page to my app (bot). As per Facebook documentation:

When you create a subscribed_apps edge, the page-id you use in endpoint must match the page ID of the page access token used in the API call. The app that the access token is for is installed for the page.

Given the call has no other parameter than the access token, this access token has to be enough for Facebook to:

  1. Authorize the action on the page.
  2. Identify what app is being subscribed to the page.

This is confirmed while using the Facebook Graph API Explorer, where one selects the page and the app to bind and a proper access token is generated:

Token is build based on page and app that will subscribe to the page.

This token properly works using cURL in the terminal:

$ curl -X POST 'https://graph.facebook.com/v3.0/<MY_APP_ID_HERE>/subscribed_apps?access_token=<TOKEN_PASTED_FROM_GRAPH_API_EXPLORER>'
{"success":true}

With the Facebook Access token debugger (info icon on the left of the access token, then open in Access token tool), it is confirmed that the token knows about both the page and the app that have to be connected.Token  has page and app info.

The question is, how are these page-app related token programmatically produced? I can’t seem to find the proper API call in Facebook documentation and it is by all means possible, as Chatfuel and Manychat are doing this.

Thanks in advance for your support Lars Schwarz and community!

2

Answers


  1. Chosen as BEST ANSWER

    Adding some detail to Alex's answer, for it to be more complete.

    When subscribing an app to a page, Facebook needs to:

    1. Know what app you are talking about.
    2. Know what page you are talking about.
    3. Know that you have permissions on that page to subscribe an app.

    How does Facebook know it all?

    1 comes from the fact that Facebook login happens in the context of a page, actually, the Javascript code for Facebook contains your appId:

    js.src = 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.0&appId=<YOUR_APP_ID_IS_HERE>&autoLogAppEvents=1';
    

    2 Comes from the page_id in the URL used to subscribe apps to pages:

    https://graph.facebook.com/v3.0/YOUR_APP_ID_HERE/subscribed_apps?access_token=YOUR_ACCESS_TOKEN_HERE

    3 Comes from the access token, obtained in the context of an APP through Facebook login, that is passed as parameter in the URL used to subscribe apps to pages:

    https://graph.facebook.com/v3.0/YOUR_APP_ID_HERE/subscribed_apps?access_token=YOUR_ACCESS_TOKEN_HERE


  2. To do this, you need to put FB Login on your site/customer portal and request pages_messaging and manage_pages permissions. The person that logs in must be a Page Admin.

    Once your app has been granted that permission for the page, you can generate a page access token as described here:

    https://developers.facebook.com/docs/pages/access-tokens

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search