简体   繁体   中英

$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

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

Solved it by moving the script to another subdirectory on the server... /login/ became /facebook/login/

I haven't got the slightest clue why that makes a difference...

    $facebook = new Facebook(array(
        'appId' => '***************',
        'secret' => '**************************',
        'cookie' => false //add this and try
        ));

and try adding permission "read_stream" check this after clearing your browser cookies..

Its Happen to me and when i check my apache log i found this :

tail -f for apache log

And i found its an SSL problems when communicate with Facebook via PHP SDK (using Curl). You have to set CURL_OPTS "CURLOPT_SSL_VERIFYPEER" to "false" .

Ex:

facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM