Search code examples
androidfacebookfacebook-graph-apifacebook-access-tokenfacebook-sdk-3.0

Facebook SDK: Access token


I'd like to get an access token without user login.

Standard way is that the user logs in and gets an access token.

But I need the access token to view events of an official page. When I try without access token, the Graph API gives me the following error:

{
    "error": {
        "message": "An access token is required to request this resource.",
        "type": "OAuthException",
        "code": 104
    }

}

So my question: Is there any way to get an access token without explicitly logging in or is there maybe another way to get event information without access token?

Thanks so far :)


Solution

  • You can get the never-expiring-access-token for your page and use that with your call. (without explicitly logging, since you are the admin of the page). Follow the 2 steps: get the extended user (admin) token and then the never expiring page token

    1. Extending the user's access token

      You can exchange the user's access token with the long-lived access token (2-months) validity. Go though the link to get the long-lived token.

      Extending tokens

    2. Extending the page's access token

      Make the following call using the long-lived user's access token and permission: manage_pages you obtained in the above step-

      $facebook->api("/PAGE_ID?fields=access_token");
      

      You'll get the never-expiring-page-token with this. (You can use Facebook's Debug Tool to check the validity of the token)