I am having login using facebook functionality in my site. The issue is after getting successful authentication the $facebook->getUser() method returning 0, due to this it’s not preceding towards the rest of code. To resolve this issue I modified my APP ID and Secret Key, also I created new APP but still its not working. Also did lot of stuff on google but didn’t got any success.
Following is my code :
public function facebookregisterAction() {
require 'auth/src/facebook.php';
$facebook = new Facebook(array('appId' => 'xxxxxxxxxxxxxxx','secret' => 'xxxxxxxxxxxxxxxxxxxxxxx','cookie' => true));
$session = new Zend_Session_Namespace('user');
$user = $facebook->getUser();
if ($session->islogout != 1) {
if ($user) {
try {
$user_profile = $facebook->api('/me');
}catch(Exception $e){}
}
}
Thanks
As a general answer, I found it helpful to start with example.php in the facebook-php-sdk directory.
In my case my test application’s URL was different than the site URL. The example.php file provided an error message that was useful enough to diagnose and correct the issue.
It’s also a good example of actual usage.
With that said, there’s a part that you seem to be missing. The user will have to visit your app’s Facebook login URL before the API will be very useful (beyond fetching public information). To find this URL, try:
You can give the user a link to click, or quietly redirect the user to this URL if you’re requiring a login. A “Hello, World!”-type start would be something like:
But you’ll quickly run into something that is covered by the example.php file: the “access token” (like a session ID) isn’t cleared when the user logs out of Facebook. Your application will still see a valid user object, but any API call that hits Facebook will fail.