无法在facebook api 4.0.1上获得字段许可

时间:2014-05-07 20:37:58

标签: php facebook facebook-graph-api facebook-php-sdk facebook-graph-api-v2.0

我正在使用

        $request = new FacebookRequest($session, 'GET', '/me');
        $response = $request->execute();
        $graphObject = $response->getGraphObject();

在我的应用上访问我的个人资料数据(我已经接受了该应用对get my primary email address权限的具体请求)

我没有在回复中收到任何电子邮件字段。但它适用于我创建的任何测试用户。我错过了什么?

更奇怪:我跑的时候

    $request = new FacebookRequest($session, 'GET', '/me/permissions');
    $response = $request->execute();
    $graphObject = $response->getGraphObject();
    var_export($graphObject);

我明白了:

Facebook\GraphObject::__set_state(array(
   'backingData' => 
  array (
    0 => 
    stdClass::__set_state(array(
       'permission' => 'public_profile',
       'status' => 'granted',
    )),
  ),
))

如果我已明确将电子邮件权限添加到"请求的权限"在应用程序的设置?

5 个答案:

答案 0 :(得分:2)

解决。

必须切换

$helper->getLoginUrl();

$helper->getLoginUrl(
    array(
        'scope' => 'email'
    )
);

('scope'必须包含逗号分隔列表的所有权限)

答案 1 :(得分:1)

我会在这里使用Graph Explorer来查看您可以/应该返回的内容:https://developers.facebook.com/tools/explorer/

电子邮件列在“扩展权限”选项卡下。

您是如何记录用户的?您应该传递范围,包括'电子邮件'到getLoginUrl方法。

答案 2 :(得分:1)

我在SDK 4-dev中做了类似的事情并且正在运行

//permissions request
$request = new \Facebook\FacebookRequest(
    $session,
    'GET',
    '/me/permissions'
);
$response = $request->execute();
$graphObjectPermissions = $response->getGraphObject()->asArray();
//echo '<pre>' . print_r( $graphObjectPermissions,1 ) . '</pre>';

$permissions = [];//create permissions array

foreach ($graphObjectPermissions as $key => $permObject) {
    $permissions[$permObject->permission] = $permObject->status;
}

//check for email permission
if (array_key_exists('email', $permissions ) &&  $permissions['email']=='granted') {
    echo '<pre> email permission granted </pre>';
} else {
    echo '<pre> email Permission denied </pre>';
}

答案 3 :(得分:0)

public function getLoginUrl($ scope = array(&#39; email&#39;),$ version = null)public function getLoginUrl($ scope = array(&#39; email&#39;),$ version = null )public function getLoginUrl($ scope = array(&#39; email&#39;),$ version = null)public function getLoginUrl($ scope = array(&#39; email&#39;),$ version = null)public function getLoginUrl($ scope = array(&#39; email&#39;),$ version = null)public function getLoginUrl($ scope = array(&#39; email&#39;),$ version = null)public function getLoginUrl ($ scope = array(&#39; email&#39;),$ version = null)public function getLoginUrl($ scope = array(&#39; email&#39;),$ version = null)public function getLoginUrl($ scope = array(&#39; email&#39;),$ version = null)public function getLoginUrl($ scope = array(&#39; email&#39;),$ version = null)public function getLoginUrl($ scope = array(&#39; email&#39;),$ version = null)public function getLoginUrl($ scope = array(&#39; email&#39;),$ version = null)public function getLoginUrl($ scope = array( &#39;电子邮件&#39;),$ version = n ULL)

答案 4 :(得分:-1)

在FacebookRedirectLoginHelper.php中查看90行...它看起来像

public function getLoginUrl($ scope = array(),$ version = null)

我改变了

public function getLoginUrl($ scope = array('email'),$ version = null)

并且工作!!!

问候!!!!