I couldn't leave it alone! So I added the authorization code to the index.php file from my previous post. Here is the latest code:
$config = array();
$config['appId'] = $app_id;
$config['secret'] = $app_secret;
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config); // constructor will start the PHP session
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
} else {
//
// no user! attempt to authorize using new OAuth2.0 garbage
//
$params = array(
'scope' => 'publish_actions, email',
'redirect_uri' => 'http://apps.facebook.com/piratestradewinds/',
'canvas' => 1
);
$loginUrl = $facebook->getLoginUrl($params);
// redirect to login
echo("<script> top.location.href='" . $loginUrl . "'</script>");
}
The problem encountered when adding the code for when $user == null was in the redirect_uri parameter for the call to getLoginUrl(). The desired behavior is after the authorization, the user is redirected to your app within facebook. DO NOT use the Canvas URL but instead use the "Canvas Page" from your app's basic settings page.
AND! Don't forget the trailing slash as well else youll get the infamous "URL does not belong to your application" error from Facebook.
Now this knowledge will live forever, here, on the internet... Until Facebook changes everything AGAIN, in 2 days. Maybe they're changing it right now! /paranoia /sigh
What is the difference between a canvas app and a page tab app??
ReplyDeleteGood question! Never looked into page tabs much... I think theyre a kind of app for Facebook pages like bands or corporate brands.
ReplyDelete