Getting friend_likes in a single API call - facebook

For a single user of my app, I want to find the likes of all his/her friends. Assuming my app requires the user to approve the app access to the friends_likes permission, is it possible to get the likes of all his/her friends in a single (or a few) API calls? This article suggests I have to make one call per friend of my user; I'd like to avoid this if possible since one user may have upwards of 1000 friends. Thanks.

Yes. You could do it in one FQL query:
SELECT name, page_id
FROM page
WHERE page_id IN
(SELECT page_id
FROM page_fan
WHERE uid IN
(SELECT uid2 FROM
friend
WHERE uid1 = me()
)
)

Related

Facebook Graph API mutual_friend_count?

So it seems FQL had a field on each user called mutual_friend_count. Is there any way to get this through the graph API?
I can get mutual friends, but I am trying to sort and cull the list when a user has below a certain number of mutual friends. Using 'mutualfriends' with the friends call takes forever and returns way too much data, I only need the count of each user, not a list of every friends mutual friend.
Am I going to have to resort to using FQL to grab this or am I missing something?
EDIT:
So it seems my best bet seems to be FQL - this gives me all my current users friends that have 200 friends in common, ordered by mutual friend count. My question is just whether this can be done directly via the Graph API.
SELECT uid, name, mutual_friend_count FROM user
WHERE uid IN (SELECT uid1 FROM friend WHERE uid2 = me())
AND mutual_friend_count > 200
ORDER BY mutual_friend_count DESC LIMIT 10

fql not working

I have used a fql for get my friends information
SELECT uid,name,first_name,middle_name,last_name,pic_square,hometown_location,current_location,profile_url,email,website FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
it returning only friends id an name. Who have trusted my app there location also comming but when I am puting this fql on the Graph API Explorer
on facebook then it returns every one's location. Then How Can I get every one's location ?
It is hard to understand your question, though it looks like your app doesn't have all the required user permissions. The Graph API explorer, or the developer page are great resources to figure out which ones you need.
Hometown location,current location, email, and website are not "basic" data.

Get friend app user with graph API

I want to get friend app user with Graph API I tried to user with me/friends?fields=installed but I got all of my friends. Maybe, I have some wrong in here. Please show me any way to get friend app user with Graph API. I don't know in Facebook SDK 3.0 can I get that list easier?
You can get list of friends whom are user of your app using FQL rather than Graph API as:
SELECT uid FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
AND is_app_user = 1

Convert Facebook API batch request into FQL multiquery

My web app builds a batch request to the Facebook graph API. The batch is composed by making a first API call to grab the user's friends. Then I loop over the list of friends and add a specific request for each (with that user's specific access token) and add each one to the batch. So it ends up being two API calls. Unfortunately, it's REALLY slow, and I've heard the FQL requests are faster.
So my question is, can I do this with FQL? I've read the documentation but I can't figure out how I might return, for example, all the friends of friends' work history (which requires each friend's access token) with one single FQL query. Is this possible? Obviously I could build a batch request of FQL requests, but that would leave me back where I started.
UPDATE:
I've done some tests and FQL definitely seems to be faster than a batch request. My FQL multiquery looks like this:
$multiQuery = array(
"query1"=>"SELECT uid2 FROM friend WHERE uid1 = me()", //LIST OF FRIEND IDs
"query2"=>"SELECT uid, name, work, education, is_app_user FROM user WHERE uid IN (SELECT uid2 FROM #query1)", //FRIEND PROFILES
"query3"=>"SELECT uid2 FROM friend WHERE uid1 IN (SELECT uid FROM #query2 WHERE is_app_user=1)",
"query4"=>"SELECT uid, name, work, education FROM user WHERE uid IN (SELECT uid2 FROM #query3)"
);
$multiQueryResult = $facebook->api(array(
'method' => 'fql.multiquery',
'queries' => $multiQuery
));
var_dump( $multiQueryResult );
The query works but there are two problems:
query3 returns all the user ids, NOT just the ones who've authorized
my app.
query4 doesn't return the work/education fields... presumably
because the API request is being called with the current user's
access token (as opposed to that of specific user from query3). I've stored the authorized users' access tokens in the DB, but I don't know if it's possible to use them in this context.
CAN this be done with FQL?? Can I define unique access tokens within an FQL multiquery?
all the friends of friends' work history (which requires each friend's access token)
If you need different access tokens, then obviously there’s no way of doing it in one single request … but where would you get each of my friends access tokens anyway, if they wouldn’t have interacted with your app themselves recently? And if they would have, you could’ve gotten their work info then already and put it into your own database, so that you could get it from there just using the uids of my friends for lookup. Otherwise, I think this is not really your way to go.
It’d rather be this way:
If friends of your user have set up their privacy settings so that they are willing to share their work info with apps your user is using, then you can get that info without requiring an individual access token for each one of those friends. Then you would just do an FQL query like this,
SELECT uid, name, work FROM user WHERE uid IN
(SELECT uid1 FROM friend WHERE uid2 = me())
That’ll give you your user’s friends work info – but obviously only for those that are willing to share that info with apps a friend is using.
This isn't really an answer to my original question because there doesn't appear to be one. It seems that at the time of writing this, the Facebook batch request is just really slow... which is too bad since that basically defeats its entire purpose.

What is the most efficient query to get all friends' events in Facebook?

I'm trying different variations of getting all friends events on Facebook. What is the most efficient query for doing so in terms of fastest respond time from Facebook. I need to get all the events my or one of my app user's friends are attending or maybe attending.
I need to get all the events my or one of my app user's friends are attending or maybe attending.
Query the FQL event_member table (http://developers.facebook.com/docs/reference/fql/event_member/) using the uid=me() (me() refers to the current user for whom the access token belongs to) and check the rsvp_status to be either 'attending' or 'unsure'.
here is the fql for grabbing all friends events, You need the friends_events permission in order to get the events
SELECT eid,name,pic,start_time,end_time,location,venue.id,privacy,all_members_count,creator,description,attending_count,can_invite_friends FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 =me()) AND start_time >= now() OR uid ='".$user_arr['fbuid']."') and privacy='OPEN' and venue.id<>'' AND start_time >=now() ORDER BY start_time ASC limit 5000