Page tab app, redirecting user back to restricted page on authentication

769 views Asked by At

I can use the following code to redirect a user back to the page my app is installed on using the following code:

$facebook = new Facebook(array(
  'appId' => $app_id,
  'secret' => $app_secret,
  'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$page = $signed_request['page'];
$page_id = $page['id'];

$page_array = $facebook->api("/$page_id");
$page_link = $page_array['page_link'];

$redirect_uri = $page_link . '?sk=app_' . $app_id

$user = $facebook->getUser();
if(!$user) {
  $url = $facebook->getLoginUrl(array('redirect_uri' => $redirect_uri));
  echo "<script type='text/javascript'>top.location.href = '$url';</script>";
}

This works fine for most pages but if a page has age restrictions (and I cant guarantee all the pages using my app won't) the $facebook->api("/$page_id"); returns false because from what I can gather, I need the users access token in order to get this information which I can't get unless I authenticate them! Is there any way around this paradox or am I going to have to instruct my users not to age restrict their pages?

UPDATE

I realise I can simply redirect to facebook.com/$page_id which will take the user back to the page after authentication and would save me having to make the api request for $page_link but ideally I would like them to be redirected to my apps page tab on that page no matter what the specified default landing tab is.

0

There are 0 answers