質問

I'm using

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

to access my profile data on my app (I've accepted the app's specific request for permission to get my primary email address)

I don't get any email field on the response. It works with any test user I create, though. What am I missing?

Even more weird: When I run

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

I get:

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

How come the email permission is not even on the list, when I have explicitly added it to "requested permissions" on the app's settings?

役に立ちましたか?

解決 2

I would use the Graph Explorer here to see what you can/should get back: https://developers.facebook.com/tools/explorer/

email is listed under the Extended Permissions tab.

How did you log the user in? You should pass in the scopes including 'email' to the getLoginUrl method.

他のヒント

Solved.

Had to switch

$helper->getLoginUrl();

for

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

('scope' must contain all permissions on a comma separated list)

I did something like this in SDK 4-dev and is working

//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>';
}

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

see the 90 line in FacebookRedirectLoginHelper.php ... it looks like

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

I change by

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

and works!!!

Regards!!!!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top