1

So I am creating an app that pulls the events from a page I manage and generates a calendar. Obviously there is no need for the client viewing this page to ever see a login screen since I just want to show my pages.

My issue is it seems all the access tokens expire, because they expect a login from the client. Is there a way to circumvent this? I dont want to have to request a new token every 60 days so I can access my data.

2
  • Additionally if the page is public and so are the events, why do I even need an access token? Commented Jun 10, 2014 at 13:32
  • Nevermind I figured it out. For those that stumble into this issue, you have to use $session = FacebookSession::newAppSession(); Commented Jun 10, 2014 at 13:49

1 Answer 1

1

There are two solutions to this problem. If the events are public and there is no age restriction on the page, you can use an app_access_token to call the API and retrieve the events.

You can do this by starting an newAppSession:

FacebookSession::newAppSession();

The second option is to log an admin into your app and use a long lived access token to call the API. This required the administrator to log-in at least once but the token will not expire unless the admin changes their password or revokes the app.

Once the user is logged in, you can call:

// get long-lived session
$long_session = $session->getLongLivedSession();

// set page access_tokens
$request = new FacebookRequest( $long_session, 'GET', '/me/accounts' );
$response = $request->execute();
// get response
$page_tokens = $response->getGraphObject()->asArray();

This will return a list of long-lived page access_tokens that can be used to then call the Events API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.