9

Is there anyone who knows how to get a friends list of email address using Facebook PHP SDK?

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
Mang Jose
  • 115
  • 1
  • 1
  • 2

6 Answers6

9

You cannot do that

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

email field only available for the users that connected to your application and have given email extended permission

zerkms
  • 249,484
  • 69
  • 436
  • 539
  • 3
    @Mang Jose: if every your friend is connected to your application and each of them has given you a `email` permission - then you can get the `email` property of their `user` object. The extended permission name is (ta-dah) `email`, and you can get the details on the link I gave above – zerkms Jan 10 '12 at 02:44
  • 1
    but there is no email listed for Extended Permissions base on http://developers.facebook.com/docs/reference/api/permissions/ – Mang Jose Jan 10 '12 at 03:00
  • @Mang Jose: oops, not `extended`, but the general `user` permission. The first table – zerkms Jan 10 '12 at 03:09
  • 1
    I am not seeing any straight forward statement at permissions section on facebook. Can you please let me know where this statement is mentioned? Note: There is no way for apps to obtain email addresses for a user's friends. – msmq Jan 15 '16 at 14:56
  • @sfarbota thanks for the downvote of an answer that was valid before, I highly appreciate that. Surely, it's my obligation to go through every one of my thousands of answers and check whether they are still valid or not. – zerkms Jun 12 '16 at 21:57
  • @sfarbota http://stackoverflow.com/help/privileges/vote-down In a case when an answer became outdated (due to changes in a 3rd party API or anything else) I personally think it would be more suitable to update an answer with clarification on why it's not accurate anymore. – zerkms Jun 12 '16 at 22:26
  • @sfarbota PS: are you *sure* the answer is no longer true? I just checked the documentation (including your quote) and the Graph API explorer - and it still works as I explained. – zerkms Jun 12 '16 at 22:28
  • @sfarbota hehe. Well, even "you cannot do that" part is still correct, since you cannot do that. – zerkms Jun 12 '16 at 23:13
6

No, apps can not get friend emails as stated in Email Permissions document. Quote from document:

Note: There is no way for apps to obtain email addresses for a user's friends.

Bao Le
  • 16,643
  • 9
  • 65
  • 68
3

A user's email is a protected property and access to that information must be specifically requested by the app and granted by the user.

Note: There is no way for apps to obtain email addresses for a user's friends.

Ashisha Nautiyal
  • 1,389
  • 2
  • 19
  • 39
1

There is no way for apps to obtain email addresses for a user's friends. See the documentation https://developers.facebook.com/docs/reference/login/email-permissions/

Narek Safaryan
  • 140
  • 1
  • 7
1

you have access to the user's friend list. Since these friends may not have authorized your application, you are only able to access a more limited set of data by default: only name, profile picture, gender, networks. Most other parts of the Facebook profile (e.g. interests, checkins, groups) are available via the Graph API if the user has granted you specific permissions. This applies to both the user's info as well as his/her friends' info. information is available subject to the user's privacy settings.

VISHNU
  • 948
  • 8
  • 15
1

Get information from this links:

Procedure

Statckoverflow discussion

If the user/friend has not given your app email permissions, chances are you won’t be able to get the email address. For instances like these, you can opt to filter just the friends who have given your app permissions. This can be done using the is_app_user field:

SELECT uid, first_name, last_name FROM user 
  WHERE is_app_user = 1 AND uid IN (SELECT uid2 FROM friend WHERE uid1 = $userId)

Get Updated Answer:

$appId     = 'YOUR_APP_ID';
$appSecret = 'YOUR_APP_SECRET';

$userId          = 'A_FACEBOOK_USER_ID';
$userAccessToken = 'THE_FACEBOOK_USER_ACCESS_TOKEN';

$client = new Facebook(array('appId' => $appId, 'secret' => $appSecret));

// get all friends who has given our app permissions to access their data
$fql = "SELECT uid, first_name, last_name, email FROM user "
     . "WHERE is_app_user = 1 AND uid IN (SELECT uid2 FROM friend WHERE uid1 = $userId)";
$friends = $client->api(array(
  'method'       => 'fql.query',
  'access_token' => $userAccessToken,
  'query'        => $fql,
));

// make an array of all friend ids
$friendIds = array();
foreach ($friends as $friend) {
  $friendIds[] = $friend['uid'];
}

// get info of all the friends without using any access token
$friendIds = implode(',', $friendIds);
$fql = "SELECT uid, first_name, last_name, email FROM user WHERE uid IN ($friendIds)";
$friends = $client->api(array(
  'method' => 'fql.query',
  'query'  => $fql,
  // don't use an access token
));

// we should now have a list of friend infos with their email addresses
print_r($friends);
Community
  • 1
  • 1
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226