I am trying to integrate Facebook into a web app that I am working on. I got an api key and secret key from Facebook, and have set the Site Url to http://www.mysite.com/something/app/
The following code is used from http://www.mysite.com/something/app/signup/xxxx/ to detect whether the user is connected or not:
$facebook = new Facebook(array(
'appId' => FB_APIKEY,
'secret' => FB_SECRETKEY,
'cookie' => true
));
$session = $facebook->getUser();
if($session) {
# Active session, let's try getting the user id (getUser()) and user info (api->('/me'))
try{
$uid = $facebook->getUser();
$user = $facebook->api('/me');
} catch (Exception $e){}
if(!empty($user)){
# User info ok? Let's print it (Here we will be adding the login and registering routines)
echo $user;
} else {
# For testing purposes, if there was an error, let's kill the script
die("There was an error.");
}
} else {
# There's no active session, let's generate one
$login_url = $facebook->getLoginUrl();
header("Location: ".$login_url);
}
But the problem is, when the user is redirected to $login_url, it keeps redirecting back, creating an infinite loop.
I have looked at other similar issues on SO, and also on Google and have tried their solutions but it just didn’t help me out.
[UPDATE]
Ok I think I am onto something. If I log in as a different Facebook user, I am not being redirected in a loop. It seems to happen only when I use my own Facebook account, which is the admin of the app. But after the redirect it should return getUser() right.. but it doesn’t for some reason.
Any ideas? Thanks.
I started from scratch on a new .php file from the root of my server. There everything was working alright, so I found out that my own code was causing the webpage to redirect.
In fact, it was the mod_rewrite in my .htaccess file that as messing things up. Somehow it is not picking up the GET variables set by FB. So I need to figure out something for it. But at least I now know what caused the problem. Case closed!