I've got a login with facebook on my website. This has worked well for some time but yesterday suddenly stopped working. I've tracked the problem to the getUser() method which seems to always returns 0 now.
my code looks like:
<?php
require_once('facebook.php');
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
));
$user = $facebook->getUser();
if ($user) {
try {
$profile = $facebook->api('/me');
$logoutUrl = $facebook->getLogoutUrl(
array(
'next'=>$baseUrl.'/fblogin/fblogin.php?logout'
)
);
$userIsLoggedIn=true;
} catch (FacebookApiException $e) {
echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
$user = null;
$loginUrl = $facebook->getLoginUrl(
array(
'scope'=>'email,publish_stream',
'redirect_uri'=>$returnAfterLoginUrl
)
);
}
}else{
$loginUrl = $facebook->getLoginUrl(
array(
'scope'=>'email,publish_stream',
'redirect_uri'=>$returnAfterLoginUrl
)
);
}
?>
What I've tried (and could find back in my history)
I'm using PHP Version 5.3.3
I've been trying to get it working since yesterday afternoon, without any luck :(
Does anyone know what might be the problem and more importantly, what might be the solution?
Thank you
Your port 80 or port 241 may be blocked causing a CurlException 7. To check that just upload the example file in your website. It will show the error.
In my case, I had my beta domain hosted on 000webhost.com. It had recently blocked the port 80 which caused the same error. When I moved my domain to another hosting service, the problem was solved.
I hope this helps.
=====EDIT=====
The solution to the problem is that (I think although it is not proven) get an https connection as it my observance that the php sdk does not work in an http connection. Look at my question here
======YEAH! THE FINAL AND CORRECT ANSWER AT LAST=======
This situation can only arise when cURL has been disabled by your web host(applicable for 100% of the cases of similar problem). Your website will run properly if cURL is installed. Usually, the error that users receive (if errorreporting is turned on) is
Fatal error: Uncaught CurlException: 7: couldn't connect to host thrown in /home/.../base_facebook.php on line ...
Make sure sandbox mode is disabled and recheck your settings again including appId, secret .
and try changing your login url to $loginUrl = $this->facebook->getLoginUrl($pram);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With