I\'m trying to get into making Facebook apps but I\'m having trouble getting authorization working in a redirect scheme inside the canvas.
Using the javascript api,
Using FB Javascript SDK, it can be done something like --
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
loggedIn(response);
} else {
top.location = encodeURI("https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_APP_URI&response_type=token");
}
The problem is that server side redirection is only redirecting your inner app frame instead of redirecting the whole page, and Facebook doesn't like displaying their system dialogs inside frames.
You would need some client side redirection, probably something along those lines:
<script>
<?php
if($doRedirect) {
echo 'top.location="http://redirect_url";';
}
?>
</script>
Maybe this helps :
if(!$facebook->api_client->users_isAppUser())
{
?>
<fb:redirect url="http://www.facebook.com/login.php?v=1.0&api_key=111111111111&next=http%3A%2F%2Fapps.facebook.com%2Fapp_name%2F&canvas=&req_perms=publish_stream"/>
<?php
}
I know that this is months old now... but this is what you should do to add permission checking to your canvas.
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$accesstoken=$session['access_token'];
} catch (FacebookApiException $e) {
error_log($e);
}
}
if($me)
{
// do what you have to do
}else {
$loginUrl = $facebook->getLoginUrl(
array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'publish_stream'
)
);
echo '<script>top.location="'.$loginUrl.'";</script>';
//echo '<fb:redirect url="' . $loginUrl . '" />';
//header('Location: '.$loginUrl);
}