Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$facebook->getUser() suddenly stopped working

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)

  1. Update the SDK to the latest version
  2. Solution of Facebook PHP SDK - getUser() suddenly returns 0 (adding 2 $CURL_OPTS)
  3. Solution of suddenly, getUser became to return 0.(PHP 3.1.1 SDK) (adding base_domain to $DROP_QUERY_PARAMS)
  4. Solution of Facebook login is suddenly not working anymore? (increasing curlopt_connecttimeout)
  5. Creating a new app, without luck

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

like image 265
user6 Avatar asked Dec 16 '22 09:12

user6


2 Answers

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 ...

like image 70
h2O Avatar answered Jan 02 '23 13:01

h2O


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);

like image 28
drarkayl Avatar answered Jan 02 '23 13:01

drarkayl