views:

549

answers:

2

I'm using the Graph API, but I can't figure out how to get a logged-in users email address.

The intro to Graph states "The Graph API can provide access to all of the basic account registration data you would typically request in a sign-up form for your site, including name, email address, profile picture, and birthday"

All well and good, but how to I access that info?

This is what I have so far:

$json = $facebook->api('/me');

$first = $json['first_name']; // gets first name
$last = $json['last_name'];
A: 

https://graph.facebook.com/me

will give you info about the currently logged-in user, but you'll need to supply an oauth token. See:

http://developers.facebook.com/docs/reference/api/user

Bobby Jack
Still does not give access to email...
kylex
you can't get it without extended permission.
grayger
+3  A: 

The only way to get the users e-mail address is to request extended permissions on the email field. The user must allow you to see this and you cannot get the e-mail addresses of the users friends.

http://developers.facebook.com/docs/authentication/permissions

You can do this if you are using Facebook connect by passing req_perms=email in the get string of your connect URL.

I'd recommend using an SDK instead of file_get_contents as it makes it far easier to perform the Oauth authentication.

Gazler
Okay, changed file_get_contents. But I'm a little confused as to where I would pass the req_perms=email.
kylex
Nevermind, I figured it out:$facebook->getLoginUrl(array('req_perms' => 'email'))
kylex