I was following the tutorial here: http://net.tutsplus.com/tutorials/php/how-to-authenticate-your-users-with-facebook-connect/
But I can’t get past the first step in allowing users to authorize my app. The app is at http://apps.facebook.com/freelancergame/ while the canvas URL is http://freelancer.xylotgames.com
I check via PHP whether there is an active session with the user. If it doesn’t exist, I redirect the user to the login URL. Here is the code at the top of the page:
// Facebook library
require 'src/facebook.php';
// Create our Application instance
$facebook = new Facebook(array(
'appId' => 'xxxxxx',
'secret' => 'xxxxxxxxxxxx',
'cookie' => true,
));
// Let's see if we have an active session
$session = $facebook->getSession();
$me = null;
// Session based API call.
if (!empty($session)) {
// Active session; let's try getting the user ID and info
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
$logoutUrl = $facebook->getLogoutUrl();
print_r($user);
exit();
} else {
// There's no active session; let's generate one
$loginUrl = $facebook->getLoginUrl();
header('Location: ' . $loginUrl);
}
The thing is, upon visiting http://apps.facebook.com/freelancergame/ I am brought to a screen with the blue Facebook logo and a link saying “Go to Facebook.com”.
However, if I allow the user to click a link to connnect with Facebook like so:
<a href="<?php echo $loginUrl ?>" target="_top">Connect</a>
…the “Allow/Don’t Allow” dialog shows up directly from Facebook’s website, but if I click “Allow” or “Don’t Allow”, it goes directly to my canvas page (http://freelancer.xylotgames.com) instead of the embedded app page, which I’d prefer.
How can I get this to work? I see apps/games that use a pop-up instead of redirection. Is this preferred? If so, how would I do it? Why won’t the NetTuts+ tutorial work for me when it most likely works for others?
I prefer the popup method (or iframe dialog inside Facebook), which you can open with the JS SDK:
Regular HTML popup:
FB.loginfunction. http://developers.facebook.com/docs/reference/javascript/fb.login/Iframe dialog:
FB.uifunction. How to show the Extended Permission Dialog in FB using new Graph API?For your redirection issue, I would double check the URLs in the configuration of the app.