facebookfacebook-graph-apiaccess-tokenfacebook-access-token

Facebook Long-Lived Pages Access Token


  1. I have created the app.
  2. I used the short-lived user access token to get a long-lived user access token.
  3. Then I tried to exchange the long-lived user access token for a long-lived page access token.
  4. This is the response I am getting:
    {
     "error": {
        "message": "(#15) This method must be called with an app access_token.",
        "type": "OAuthException",
        "code": 15,
        "fbtrace_id": "AaKKgfwJzZsNDXADht1N7wy"
     }
    }
  1. This is the endpoint for the API call to receive a long-lived page access token:
https://graph.facebook.com/v19.0/{app-id}/accounts?access_token={long-lived-user-access-token}
  1. The endpoint for long-lived user access token:
https://graph.facebook.com/v19.0/oauth/access_token?grant_type=fb_exchange_token&client_id={app-id}&client_secret={app-secret}&fb_exchange_token={short-lived-user-access-token}
  1. According to this documentation, I need to exchange a long-lived user access token in order to get a long-lived pages access token: Facebook Developer Documentation

Solution

    1. This is the endpoint for the API call to receive a long-lived page access token:

    https://graph.facebook.com/v19.0/{app-id}/accounts?access_token={long-lived-user-access-token}

    No, it's not. Accounts belong to the user object, not the application. {app-id} needs to actually be the app-scoped user id - or just me, since a user token is used for the request anyway.

    (The error message saying that it needed an app access token, is simply due to the fact that you targeted the wrong endpoint in the first place.)