Bertho Joris
Bertho Joris

Reputation: 1601

Facebook SDK Permission to access page message

How do I get a token to be able to read the data messages sent to my facebook page?

If I see here : https://developers.facebook.com/docs/facebook-login/permissions/#overview there described :

read_page_mailboxes : Enables your application to retrieve the Facebook Messages conversations for Pages. You must use a Page Access Token to do this. Conversations are retrieved by calling /{page_id}/conversations via the Graph API.

What should I do to get access to this?

Thanks

Upvotes: 1

Views: 627

Answers (1)

Fabio Antunes
Fabio Antunes

Reputation: 22862

Here's how you do it, first you need to grab the page token for your page, I'm assuming that you've already logged the user with the scope manage_pages and read_page_mailboxes

To read/respond/delete messages you must be a Full Admin, Content Creator or Moderator

Page admins have different roles, which is indicated by the perms array returned as above. The functionality available to them is decided based on the following perms values:

You can read more about it here: https://developers.facebook.com/docs/facebook-login/access-tokens/#pagetokens

Now for the code you need to get the page access token:

//get user accounts    
$pages = $this->facebook->api('/me/accounts');
foreach ($pages['data'] as $page) {
    if($page['id']==PAGE_ID_YOU_WANT){
        //the user is admin of the page you want
        $page_access_token = $page['access_token'];
        $page_conversations = $facebook->api('/PAGE_ID_YOU_WANT/conversations', 'GET', array('access_token' => $page_access_token));
    }

}

Upvotes: 2

Related Questions