Facebook PHP Login SDK - how get Email address only name getting

In Facebook PHP Login SDK - how get Email address only name & id getting below…var_dump($response);… well?
I implemented two php files here : https://developers.facebook.com/docs/php/howto/example_facebook_login/5.0.0 and added to the END OF /fb-callback.php I HAVE PUT THE BELOW IN THE HOPE TO GET RESULT EMAIL, HOW GET EMAIL ADDRESS…?
(IN JS SDK FACEBOOK DO GETTING EMAIL BUT I WANT IN PHP ALSO)

$fb->setDefaultAccessToken($_SESSION[‘fb_access_token’]);

try {
  $response = $fb->get('/me',$_SESSION['fb_access_token'],['fields' => 'id,name,email,address,first_name,last_name']
);
  $userNode = $response->getGraphUser();
} 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;
}

echo '<BR/>Logged in as ' . $userNode->getName() .'<br/><br/><br/><br/>';



var_dump($userNode);

var_dump($response);
?>

What results do you get in your two var_dumps?

Metadata
object(Facebook\Authentication\AccessTokenMetadata)#13 (1) { [“metadata”:protected]=> array(7) { [“app_id”]=> string(16) “yyyyyy” [“application”]=> string(14) “rrrrrrrrrrrrrrrrrrr” [“expires_at”]=> object(DateTime)#17 (3) { [“date”]=> string(26) “2015-12-06 10:20:43.000000” [“timezone_type”]=> int(3) [“timezone”]=> string(13) “Europe/London” } [“is_valid”]=> bool(true) [“issued_at”]=> object(DateTime)#18 (3) { [“date”]=> string(26) “2015-10-07 11:20:43.000000” [“timezone_type”]=> int(3) [“timezone”]=> string(13) “Europe/London” } [“scopes”]=> array(4) { [0]=> string(12) “user_friends” [1]=> string(5) “email” [2]=> string(15) “publish_actions” [3]=> string(14) “public_profile” } [“user_id”]=> string(15) “yyyyyyyyy” } }
Logged in as Dorothy Alajdehfjacgf Rosenthalescu

object(Facebook\GraphNodes\GraphUser)#22 (1) { [“items”:protected]=> array(2) { [“name”]=> string(35) “Dorothy Alajdehfjacgf Rosenthalescu” [“id”]=> string(15) “101216123570341” } } object(Facebook\FacebookResponse)#21 (6) { [“httpStatusCode”:protected]=> int(200) [“headers”:protected]=> array(14) { [“Access-Control-Allow-Origin”]=> string(1) “*” [“Content-Type”]=> string(31) “application/json; charset=UTF-8” [“X-FB-Trace-ID”]=> string(11) “CnABQoREizW” [“X-FB-Rev”]=> string(7) “1975367” [“ETag”]=> string(42) ““yyyyyyyyyyy”” [“Pragma”]=> string(8) “no-cache” [“Cache-Control”]=> string(44) “private, no-cache, no-store, must-revalidate” [“Facebook-API-Version”]=> string(4) “v2.4” [“Expires”]=> string(29) “Sat, 01 Jan 2000 00:00:00 GMT” [“Vary”]=> string(15) “Accept-Encoding” [“X-FB-Debug”]=> string(88) “wTko07uWRW10kecXs+KwcwvQaM+yyyyyyyyyyyyy+kGNscShMplg/AGbw==” [“Date”]=> string(29) “Wed, 07 Oct 2015 15:46:17 GMT” [“Connection”]=> string(10) “keep-alive” [“Content-Length”]=> string(2) “69” } [“body”:protected]=> string(69) “{“name”:“Dorothy Alajdehfjacgf Rosenthalescu”,“id”:“101216123570341”}” [“decodedBody”:protected]=> array(2) { [“name”]=> string(35) “Dorothy Alajdehfjacgf Rosenthalescu” [“id”]=> string(15) “101216123570341” } [“request”:protected]=> object(Facebook\FacebookRequest)#19 (9) { [“app”:protected]=> object(Facebook\FacebookApp)#3 (2) { [“id”:protected]=> string(16) “1513065949013877” [“secret”:protected]=> string(32) “yyyyyyyyyyyyyyyyyyyy” } [“accessToken”:protected]=> string(197) “yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy” [“method”:protected]=> string(3) “GET” [“endpoint”:protected]=> string(3) “/me” [“headers”:protected]=> array(1) { [“Content-Type”]=> string(33) “application/x-www-form-urlencoded” } [“params”:protected]=> array(0) { } [“files”:protected]=> array(0) { } [“eTag”:protected]=> array(1) { [“fields”]=> string(48) “id,name,email,address,first_name,last_name,about” } [“graphVersion”:protected]=> string(4) “v2.4” } [“thrownException”:protected]=> NULL }

Are you certain the accounts you are wanting the email addresses for have their security settings set to allow returning it?

I tried fake Facebook accounts… from Facebook API roles > testers…

well any hint to try…?

you saw:

“user_friends” [1]=> string(5) “email” [2]=> string(15) “publish_actions” [3]=> string(14)

why email Not shown,… and what is Email getter other than from Array?

in JS SDK getting email but not in PHP

Also this line is important

$tokenMetadata->validateAppId($config['app_id']);   // ONLY IF COMMENTED OUT run OK otherwise getting errors

I retried and Not getting email (or Not know how) in PHP SDK FACEBOOK but get success in JS SDK FACEBOOK…

Any hint…?

I think I will use PHP & JS SDKs Facebook like in
https://developers.facebook.com/docs/php/gettingstarted/5.0.0

section
Obtaining an access token from the SDK for JavaScript
example-obtain-from-js-cookie-app.php

but you have any idea where insert this code(example-obtain-from-js-cookie-app.php) and how link it to JS?

And this is it seems correct v2.4 Graph API…?

$fb->setDefaultAccessToken($_SESSION['fb_access_token']);

try {
  $response = $fb->get('/me',$_SESSION['fb_access_token'],['fields' => 'id,name,email,address,first_name,last_name']
);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.