2

Possible Duplicate:
Facebook Graph API, how to get users email?

I am playing with Facebook API and trying to get available information from it.

$facebook = new Facebook(array('appId'  => 'id', 'secret' => 'key'));  
print_r($facebook->api('/my_username_or_id'));

which prints out:

Array ( [id] => my_id [name] => whole_name [first_name] => first_name [last_name] => last_name [link] => url_to_profile [username] => username [gender] => gener [locale] => es_LA )

But not email. When I go to Facebook developer test site and set up my username or ID, I get something like this:

{
  "id": "id", 
  "name": "name", 
  "first_name": "first_name", 
  "last_name": "last_name", 
  "link": "link", 
  "username": "username", 
  "gender": "male", 
  "timezone": 2, 
  "locale": "en_US", 
  "verified": true, 
  "updated_time": "2012-07-16T13:00:04+0000"
}

Pretty similar information like in the first case.

But again - I cannot get the email address. I've tried also

print_r($facebook->api('/my_username_or_id?fields=email'));

and the same also on FB developer site, but again without success...

Is there any way to get email address from ID/username?

Community
  • 1
  • 1
user984621
  • 46,344
  • 73
  • 224
  • 412

2 Answers2

3

To get an email address for a user, you need to have a user access token or have them authenticated in an app with the email permission granted.

This gives you the email for that user only. You can't get a user's friend's email address this way.

This prevents spammers from harvesting emails from Facebook.

cpilko
  • 11,792
  • 2
  • 31
  • 45
  • I have access token and my access token has user_friends,public_profile how to i get user email id? important thing i get user id and name of the user only one i need that is user email how to i get email from using userId? @ cpiko – Balakumar B Aug 01 '16 at 11:47
  • how to add scope to access token and how to get email? if any example or suggestion pls share – Balakumar B Aug 01 '16 at 11:49
3

By using facebook api you can only fetch your own e-mail id in your result sets. I think because of security reasons facebook doesn't provide another users e-mail ids.

Satish Pandey
  • 1,184
  • 4
  • 12
  • 32