1

My PHP Facebook SDK is not working and always returns $user=0 Why?

It is my first time to deal with facebook sdk

my code:

require './facebook-php/src/facebook.php';

$facebook = new Facebook(array(
'appId'  => 'xxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxx'
));
// Get User ID
$user = $facebook->getUser();

if ($user) {
try {
  // Proceed knowing you have a logged in user who's authenticated.
     $user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
  }
}

 if($user) {
    $logoutUrl = $facebook->getLogoutUrl();  echo 'there is a user';
} else {
 $loginUrl = $facebook->getLoginUrl();
echo 'there is noo user <a href='.$loginUrl.'>login</a>';
}

below is the url return code :
http://localhost/e-commerce/testit.php?code=AQA8DckDMqNarptbCUIfAmn2tIyn1mjVBmHTjOMaQ4GqsFW_6vqemGW35TC07Kxq7kuB4QkKibHJ2-m9GntIx0biWEiR_FUuozsONvgc_tNmtGURpcm78DnIE26vT6hbjz10eZECuh-GLec9tGplhLrDNbLO-aX2Hv2Mu-8CQhAdiFQ6AYW3Nt09a8Rzahbn35Jz0cNyB_G7Ksjorq3iSs6Bpa6Tk0d7Vx0A0f1Mg77PgD6IuN_grjkNHDWmb_ywoqW48IqoxJUhnRmL3qi1G-CT7ft_f77rRr-VP-yQ-LTkdNja0rBzoFnFGccMuQ86u8tk7nfnx5qrSLBpHLEIBqQT&state=84ff9f36e8de53d13c96bcf7cb2da3b3#=

I have uploaded Facebook setting image
Facebook settings images

Mr Pro Pop
  • 666
  • 5
  • 19
  • https://stackoverflow.com/q/21367924/1531971 https://stackoverflow.com/q/13589510/1531971 etc –  Aug 23 '17 at 18:10
  • i add CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 2 to facebookbasefile but problem Notresolved yet – Hossam Hassan Aug 23 '17 at 18:23
  • 1
    You should add what you did and the result you get to the _body_ of the question. SO is not a threaded forum. Did you check _all_ the answers I linked to? –  Aug 23 '17 at 20:13
  • That looks like code for one of the older SDK versions ... I would recommend that you first of all upgrade to the current one, which is v5. (But careful, you will have to re-write most of that code, it has changed on a large scale. But the official documentation has lots of easy examples.) – CBroe Aug 24 '17 at 07:23
  • i delete my old version of sdk v4 and use sdk v5.0 and it run successfully thank you – Hossam Hassan Aug 24 '17 at 10:57

0 Answers0