Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Facebook图形API返回空值_Php_Facebook_Facebook Graph Api - Fatal编程技术网

Php Facebook图形API返回空值

Php Facebook图形API返回空值,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,我的Facebook登录在本地主机上运行得非常好,但当我将其上传到web服务器时,它无法从用户那里获取任何数据。 我只能获取他们的facebook id,但其他信息为空或空白 我认为facebook登录是有效的,因为他们被重定向到了我初始化的$redirect\uURL $app_id = "******"; $app_secret = "*******"; $redirect_url = "localhost/sample/"; try { $facebook = FacebookS

我的Facebook登录在本地主机上运行得非常好,但当我将其上传到web服务器时,它无法从用户那里获取任何数据。 我只能获取他们的facebook id,但其他信息为空或空白

我认为facebook登录是有效的,因为他们被重定向到了我初始化的
$redirect\uURL

$app_id = "******";
$app_secret = "*******";
$redirect_url = "localhost/sample/";

try
{
    $facebook = FacebookSession::setDefaultApplication($app_id,$app_secret);
    $helper = new FacebookRedirectLoginHelper($redirect_url);
    $sess = $helper -> getSessionFromRedirect();
}
catch(Exception $e)
{

}


if(!isset($sess))
{    
    //facebook login button

    echo '<div class="fb"><a href="'.$helper->getLoginUrl().'"> <i class="fa fa-facebook"></i>Sign in with Facebook</a></div>';

}
else
{
    $request = new FacebookRequest($sess,'GET','/me');
    $response = $request->execute();                                                
    $graph = $response->getGraphObject(GraphUser::classname());                 
    $fb_id = $graph ->getId(); //this is the only data that i can get
    $fname = $graph ->getFirstName();
    $lname = $graph ->getLastName();
    $gender = $graph ->getGender();

    echo 'name: '.$fname.' '.$lname.' gender: '.$gender; // these are null or ''      

    $_SESSION['fb_session'] = $sess;
}
$app_id=“*******”;
$app_secret=“*******”;
$redirect_url=“localhost/sample/”;
尝试
{
$facebook=FacebookSession::setDefaultApplication($app\u id,$app\u secret);
$helper=newfacebookRedirectLoginHelper($redirect\uURL);
$sess=$helper->getSessionFromRedirect();
}
捕获(例外$e)
{
}
如果(!isset($sess))
{    
//facebook登录按钮
回声';
}
其他的
{
$request=newfacebookrequest($sess、'GET'、'/me');
$response=$request->execute();
$graph=$response->getGraphObject(GraphUser::classname());
$fb_id=$graph->getId();//这是我能得到的唯一数据
$fname=$graph->getFirstName();
$lname=$graph->getLastName();
$gender=$graph->getGender();
echo'name:'.$fname.'.$lname.'gender:'.$gender;//这些值为null或“”
$\会话['fb\ U会话]=$sess;
}
我已经获得批准。

这是我创建的一个fb帐户。


如上所示,我认为我没有违反任何规则,因为我只是从约定的权限中获取信息。

看起来FB要求您在请求中包含图形版本。另外,为什么不在异常中添加一些检查,看看这是图形问题还是FBSDK问题。另外,用户正在进行身份验证,而您只是没有获取他们的数据,还是他们也没有进行身份验证

以下是我使用过的一个剪贴画,它位于FB Graph auth文档中:

$fb = new Facebook\Facebook([
 'app_id' => '{app-id}',
 'app_secret' => '{app-secret}',
 'default_graph_version' => 'v2.2',
]);

$helper = $fb->getRedirectLoginHelper();

try {
  $accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
 // When validation fails or other local issues
 echo 'Facebook SDK returned an error: ' . $e->getMessage();
 exit;
}

这还可以让它从您注册的应用程序中为您获取重定向url。

看起来FB要求您在请求中包含图形版本。另外,为什么不在异常中添加一些检查,看看这是图形问题还是FBSDK问题。另外,用户正在进行身份验证,而您只是没有获取他们的数据,还是他们也没有进行身份验证

以下是我使用过的一个剪贴画,它位于FB Graph auth文档中:

$fb = new Facebook\Facebook([
 'app_id' => '{app-id}',
 'app_secret' => '{app-secret}',
 'default_graph_version' => 'v2.2',
]);

$helper = $fb->getRedirectLoginHelper();

try {
  $accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
 // When validation fails or other local issues
 echo 'Facebook SDK returned an error: ' . $e->getMessage();
 exit;
}

这还可以让它从您注册的应用程序中为您获取重定向url。

您需要在请求中包含您想要的字段。API v2.4中的更改看起来@WizKid的评论是正确的答案。我建议用修改过的代码行来完成它,并将其作为回复发布。您需要在请求中包含您想要的字段。API v2.4中的更改看起来@WizKid的评论是正确的答案。我建议用修改过的代码行来完成它,并将其作为答案发布