4

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

Community
  • 1
  • 1
user6
  • 1,999
  • 2
  • 23
  • 29

5 Answers5

9

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

Community
  • 1
  • 1
h2O
  • 544
  • 1
  • 15
  • 38
2

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

drarkayl
  • 1,017
  • 7
  • 17
  • Thank you for your reply, Sandbox mode is disabled and the settings are correct (it worked fine for weeks until yesterday). Changing the loginUrl like that won't do any good for there is no $this within my scope? – user6 Jun 25 '13 at 08:09
  • so what happens after the user is redirected to facebook login and he logs in? does it work then? – drarkayl Jun 25 '13 at 08:11
  • 1
    After the user has given the appropriate permissions to the app he returns to the site where getUser() will still return 0 :( – user6 Jun 25 '13 at 08:14
  • just remove your applicaiton from myapps and try adding it again. and just check whether your facebook object is initizlied or not try this->facebook and print your appid. – drarkayl Jun 25 '13 at 08:40
  • I've tried creating a new app, same problem :( The $facebook object is initialized and I was able to print my appid from it. – user6 Jun 25 '13 at 08:55
  • i had resolved this a few days back but looking at your code it should work....ill get back to you in an hour. I know the frustration you feel. :( – drarkayl Jun 25 '13 at 09:06
  • Facebook is evil. I´m still stuck on this and can't set a bounty yet :( – user6 Jun 26 '13 at 14:23
  • Not really, decided to just disable login by facebook for now. – user6 Jun 28 '13 at 08:18
  • give me a link to your app if its live. – drarkayl Jun 28 '13 at 08:20
1

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

user6
  • 1,999
  • 2
  • 23
  • 29
0
    $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..

0

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; 
SMSM
  • 1,509
  • 3
  • 19
  • 34