$ facebook-> api('/ me')显示我的NULL值

时间:2014-06-03 20:38:50

标签: php facebook facebook-graph-api facebook-php-sdk

我正在尝试运行此Facebook Graph API以将我的网站与Facebook连接。但每次我使用Facebook登录时,index.php页面都不会改变。它不显示来自Facebook的任何信息。当我使用var_dump时,它两次显示为NULL。

以下是代码:

$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;

    }       
}

1 个答案:

答案 0 :(得分:0)

您是否曾从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();

  }   

}

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