Why Is Facebook PHP Sdk Getuser Always Returning 0

Facebook PHP SDK - getUser() suddenly returns 0

In base_facebook.php add the following 2 lines under $CURL_OPTS:

CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2

Which makes it...

public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-3.2',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2
);

I'm not sure how much of a security issue this is, but it makes the Login with Facebook work, so there you have it.

EDIT: New SDK released which fixes this problem: https://github.com/facebook/facebook-php-sdk

Why is Facebook PHP SDK getUser always returning 0?

The answer to my specific issue was that there were incompatibilities between the versions of the JS SDK and PHP SDK I was using and just upgrading them solved it.

The symptom of this issue is similar when it's caused by a variety of different things so you may do very well in scouting through the different answers available in this page.

Facebook PHP SDK $uid = $facebook->getUser() always returns 0

In window.fbAsyncInit I have set cookie and oauth to true and this worked!

cookie:true,    
oauth : true.

Make sure that In your php you also have

cookie' => true.

That will enable the php code to integrare with the JS.

facebook->getUser() returning 0

Change this

$loginUrl = $facebook->getLoginUrl(array ( 
'display' => 'popup',
'redirect_uri' => 'http://localhost/demo'
));

to

$loginUrl = $facebook->getLoginUrl(array ( 
'display' => 'popup',
'redirect_uri' => 'http://localhost/demo/index.php'
));

And see if this works !!

Why is Facebook PHP SDK getUser always returning 0? Opencart

Try this ;)

Replace

echo $fbuser = $this->fbconnect->getUser();

with

try {
// Returns a `Facebook\FacebookResponse` object
$response = $this->fbconnect->get('/me?fields=id,name', '{access-token}');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}

$user = $response->getGraphUser();

echo 'Id: ' . $user['id'];
echo 'Name: ' . $user['name'];


Related Topics



Leave a reply



Submit