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
List of Big-O For PHP Functions
How to Convert a String to a Number in PHP
How to Measure the Speed of Code Written in PHP
What's the Maximum Value For an Int in PHP
Turning Multidimensional Array into One-Dimensional Array
Base_Url() Function Not Working in Codeigniter
Is Closing the MySQL Connection Important
How to Set Order by Params Using Prepared Pdo Statement
Pdo Valid Characters For Placeholders
Laravel 5.2 Validation Error Not Appearing in Blade
What Kind of String Is This? How to Unserialize This String
Get Value from Simplexmlelement Object
How to Initialize Static Variables
What Is the "-≫" PHP Operator Called