简体   繁体   中英

$facebook->api('/me') shows me NULL value

I am trying to run this Facebook Graph API to connect my website with Facebook. But everytime I login with Facebook, index.php page doesn't change. It doesn't display any information from Facebook. When I used var_dump, it showed me NULL both the times.

Here is the code:

$user = $facebook->getUser();

if($user){

    try{
        //get the facebook user profile data
        $user_profile = $facebook->api('/me');
        Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false; 
        Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;
        $params = array('next' => $base_url.'logout.php');
        //logout url
        $logout =$facebook->getLogoutUrl($params);
        $_SESSION['User']=$user_profile;
        $_SESSION['logout']=$logout;
    }catch(FacebookApiException $e){
        error_log($e);
        $user = NULL;

    }       
}

Have you ever follow step by step the documentation from Facebook API?

use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;

if($session) {

  try {

    $user_profile = (new FacebookRequest(
      $session, 'GET', '/me'
    ))->execute()->getGraphObject(GraphUser::className());

    echo "Name: " . $user_profile->getName();

  } catch(FacebookRequestException $e) {

    echo "Exception occured, code: " . $e->getCode();
    echo " with message: " . $e->getMessage();

  }   

}

Source: https://developers.facebook.com/docs/php/howto/profilewithgraphapi/4.0.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM