OAuthErrors when trying to read a Facebook Page's messages

1.8k Views Asked by At

I am trying to read the inbox and outbox of a Facebook Page. My first approach was to try to directly access the inbox of a page node. The URI below indicates how I tried to get it:

/{page-id}/inbox

Here is the error message:

You can only access the \"inbox\" connection for the current user.

Then I tried to access the conversations and threads edges as suggested in some places like so:

/{page-id}/conversations

/{page-id}/threads

Both URIs produce the following error:

(#298) You must be a developer of the application

I couldn't figure out what is wrong at all? There are some bug reports to Facebook, related to "#(298)", which were reported a few months ago but I can't believe it hasn't been fixed so far.

Any alternative approach is welcome.

1

There are 1 best solutions below

0
On

This problem happens if you use a user access token instead of a page access token.

I was doing this in the Facebook Graph API Explorer and I thought I was using the page access token but I wasn't. When I ran {page-id}/conversations?access_token={page_access_token} from the API Explorer, it had the {user_access_token} in the Access Token field at the top. This was being sent in the actual request that the Explorer sent (as seen in Chrome's dev tools). I.e., the API Explorer was ignoring the {page_access_token} I entered and was using the value in the Access Token field.

Clearing the Access Token field or entering the {page_access_token} in that field resulted in the intended {page_access_token} being sent. Doing some of the steps in the browser vs the API Explorer showed me the way.

These are the steps to resolve the issue:

  1. Get a user access token: with manage_pages and read_page_mailboxes permissions* by clicking Get Access Token from the API Explorer and selecting the specified permissions or visiting the URL below.

    https://www.facebook.com/dialog/oauth?client_id={app-id}&redirect_uri={redirect-uri}&request_type=token&scope=manage_pages,read_page_mailboxes
    
  2. Get a page access token: by running /me/accounts from the API Explorer or by vising the URL below.

    https://graph.facebook.com/v2.0/me/accounts?method=GET&format=json&suppress_http_code=1&access_token={user-access-token}
    
  3. Get conversations: Use the page access token (paste it in the Access Token field if using the API Explorer) from the above step to get conversations** by running /{page-id}/conversations or by vising the URL below.

    https://graph.facebook.com/v2.0/{page-id}/conversations?method=GET&format=json&suppress_http_code=1&access_token={page-access-token}
    

* read_mailbox permission is not required, contrary to what I said in my comment above. Actually, the error message was incorrect, attempting to access Page edges with a user access token incorrectly gives user access errors instead of invalid Page access token errors.

** The user must be an admin of the Facebook Page to access its conversations.