1

I have this FQL:

$femail = $facebook->api(array( 
'method' => 'fql.query', 
'locale' => 'en_US',
'query' => 
'SELECT email 
FROM user 
WHERE uid 
IN (SELECT uid2 
    FROM friend 
    WHERE uid1='.$user_id.') 
AND uid = '.$friend_id.' 
ORDER BY name ASC', ));

Here is the print_r result:

Array
(
    [0] => Array
        (
            [email] => 
        )

)

I want to get friend's email address, but this query results in empty email values. Does I miss something in query? Does it even possible to get friends email? I tested with my partner, she gave permission to the app to give out email address.

Ákos Nikházy
  • 1,276
  • 17
  • 33
  • yea you have a point where its impossible 'where uid IN' then 'AND uid =' different that cant happen its one or the other never both – Barkermn01 Feb 25 '11 at 08:06
  • And buy the looks your not allowed to http://stackoverflow.com/questions/2836866/facebook-emails-always-return-null-through-fql-and-restfb – Barkermn01 Feb 25 '11 at 08:09

2 Answers2

3

In general, you CAN'T get the email address of your friends (source):

User permission     Friends permission
email             not available

BUT but since your friend has authorized your application, you can try the following in the FQL console:

SELECT email FROM user WHERE uid=FRIEND_ID

What I suspect the problem could be is that you need the "friend's" access_token to actually get the email because I suppose you are logged-in as your user when trying your query. So you need to grant the offline_access permission and then use it with the query.

But before doing the above, I would try it with an application access_token.

P.S: the sub-query is not needed if you know the friend id.

ifaour
  • 38,035
  • 12
  • 72
  • 79
  • Thank you. This helped. With the smaller query it become faster and offline_access was needed at this time. – Ákos Nikházy Feb 26 '11 at 18:53
  • It does appear that at least one app [Facely HD](http://itunes.apple.com/us/app/facely-hd-for-facebook-chat/id392550341?mt=8) does have this functionality. They perform some kind of non-standard login, so it may be possible that they are performing an (illegal) login on their servers and scraping. – The Mad Gamer Jun 24 '11 at 02:53
  • So I tried to edit the above comment, but StackOverflow went down for a few minutes... It does appear that at least one app [Facely HD](http://itunes.apple.com/us/app/facely-hd-for-facebook-chat/id392550341?mt=8) does have this functionality - you can see a friend's email (who has not installed the app). Facely performs some kind of non-standard login, so it may be possible that they are performing an (illegal) login on their servers and scraping. I'd be curious if anyone could offer any insight. FWIW, I have no affiliation with Facely. – The Mad Gamer Jun 24 '11 at 03:01
-2

You can't get email addresses of friends. Each account must opt-in to sharing their email address with the application. Friends can't opt other friends in, which is a good thing.

Also, as @Barkermn01 mentioned, drop the AND uid = '.$friend_id.'

Brent Baisley
  • 12,641
  • 2
  • 26
  • 39
  • I am pretty sure AND is needed. How else the query knows which friends email address I want to query? (anyway I tried without AND and it gave me 31 empty email array element (I have 31 friends) ). My partner gave permission to apps to have her email address. But I still can't get it with this fql. – Ákos Nikházy Feb 25 '11 at 10:52
  • You're selecting the friends of the the "user", not the user. The uid1='.$user_id.' is what specifies which users/friends you are selecting. Email addresses are not accessible by apps unless allowed by the user. You can see your friend's email, but the app can't. Which is why you got empty values. – Brent Baisley Feb 26 '11 at 02:15
  • We can't get another user's email other than logged in one. The fb has a clause in regard to user's privacy policies. – Arpit Garg Nov 21 '12 at 12:29