$ facebook-> getUser () suddenly stopped working

I have a facebook login on my site. This worked fine for a while, but yesterday it suddenly stopped working. I tracked a problem with the getUser () method, which seems to always return 0.

my code is as follows:

<?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 tried (and could find in my story)

I am using PHP 5.3.3

I am trying to get it to work from yesterday, with no luck :(

Does anyone know what could be the problem and more importantly, what could be the solution?

thanks

+4
source share
5 answers

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

I have no idea why this matters ...

+1
source

Your port 80 or port 241 can be blocked by raising CurlException 7. To check how to upload the sample file to your site. He will show an error.

In my case, I had a beta domain hosted on 000webhost.com. He recently blocked port 80, which caused the same error. When I moved my domain to another hosting, the problem was resolved.

Hope this helps.

===== ===== EDIT

The solution to the problem is that (I think, although this has not been proven) to get an https connection, since I observe that php sdk does not work in an http connection. Look at my question here

====== YEAH! FINAL AND CORRECT RESPONSE TO THE LAST =======

This situation can only occur when cURL is disabled by your web host ( applicable for 100% of cases of a similar problem ). Your site will work correctly if cURL is installed. Usually the error received by users (if error handling is enabled) is
Fatal error: Uncaught CurlException: 7: couldn't connect to host thrown in /home/.../base_facebook.php on line ...

+9
source

Make sure sandbox mode is off and check your settings again, including appId, secret.

and try changing your login URL to $loginUrl = $this->facebook->getLoginUrl($pram);

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

and try adding the read_stream permission, check this after clearing the browser cookies.

0
source

Its happening to me, and when I check my apache log I found this:

tail -f for apache log

And I found my SSL problems when communicating with Facebook via the PHP SDK (using Curl). You must set CURL_OPTS "CURLOPT_SSL_VERIFYPEER" to "false".

Example:

 facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false; 
0
source

Source: https://habr.com/ru/post/1488019/


All Articles