iPhone facebook connect FQL Query to get user's friends - iphone

I'm trying to get a list of user's friends using fb connect for the iphone.
I've tried both of the following FQL Queries, but they don't seem to be returning anything.
which one is correct if any ?
NSString* fql = [NSString stringWithFormat:#"select flid,name from friendlist where owner=%lld",[self fbSession].uid];
or
NSString* fql = [NSString stringWithFormat:#"SELECT flid,uid FROM friendlist_member WHERE flid IN (SELECT flid FROM friendlist WHERE owner=%lld)",[self fbSession].uid];

Ah.. figured it out...
NSString* fql = [NSString stringWithFormat:#"SELECT name,uid FROM user WHERE uid IN ( SELECT uid2 FROM friend WHERE uid1=%lld )",[self fbSession].uid];

Related

Facebook SDK Unity. how to get a list of friends who play this game?

How to get a list of friends who play in my game or who install my game?
This code is not working:
string fql = "/fql?q=SELECT uid, name, is_app_user, pic_square FROM user WHERE uid IN "+
"(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1";
FB.API(fql, Facebook.HttpMethod.GET, GetListOfPlayer);
You're query is absolutely correct. I'm not sure but the problem could be that you have not urlencoded the fql query.
You can try this-
string query = WWW.EscapeURL("SELECT uid, name, is_app_user, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1");
string fql = "/fql?q="+query;

Get Facebook friends attending an event?

How am I able to see which of my friends attend a Facebook event? I'm able to get a list of all attendees using the Facebook SDK, withGraphPath:#"eventId/attending/".
Is what I want even possible using the Graph API? I read some answers on how to achieve this with FQL but don't know how to implement it in iOS. The only option I came up with is getting all friends and all attendees and cross-referencing them against each other, but that is very inconvenient.
So, how do I get only MY Facebook friends attending an event?
This is from the tutorial provided by Facebook
You can check if a specific user responded 'yes' to an event by
issuing an HTTP GET to /EVENT_ID/attending/USER_ID. These operations
require the user_events or friends_events permissions for non-public
events and return an array of objects with the name, id, and
rsvp_status fields. When checking a single user, an empty data will be
returned if the user did not respond 'yes' to the event.
You can check it by checking the event category in this link:
http://developers.facebook.com/docs/reference/api/event/
Use /EVENT_ID/attending/USER_ID to see which friend is attending to an event
Okay, so I found the solution to my problem... The only way to achieve what I want is through FQL. Basically, it cross-references your friends with the attendees but on the Facebook servers, and you only receive the data you ask for (in my case user ID, name, image). I have not figured out how to set a limit and offset, but I don't require it and I think it is possible via FQL too...
Here is my code:
-(void)getFriendsAttending{
NSLog(#"getting friends");
NSString *fql = [NSString stringWithFormat:#"SELECT uid, name, pic FROM user WHERE uid IN (SELECT uid FROM event_member WHERE eid = %# AND rsvp_status = 'attending' AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me()))", fbID];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:fql forKey:#"q"];
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:params
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSLog(#"Friends at event %#: %#", fbID, result);
}
}];
}
And here is the pure FQL query for clarity (123456789 - being the event ID):
SELECT uid, name, pic FROM user WHERE uid IN (SELECT uid FROM event_member WHERE eid = 123456789 AND rsvp_status = 'attending' AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me()))
Just utilize the {event id}/attending and then filter this based on your actual friends list.
Using FQL QUery try:
SELECT uid FROM event_member WHERE eid = YOU_EVENT_ID_HERE AND rsvp_status = 'attending'
Using Graph API:
/YOU_EVENT_ID_HERE/attending
This returns the "Attending Friends" user ID's (uid).
ASH

Fetch friends data with Graph API

I need fetch user's friends data with next fields: id, name,
gender, birthday, city, country, profileUrl, pic, pic_small,
pic_big, is_app_user.
Before I used FB.Data.query, but now it's deprecated.
FB.Data.query('select uid, first_name, last_name, name, pic,
pic_small, pic_big, birthday_date, sex, current_location,
profile_url, is_app_user from user where uid in (select uid2 from
friend where uid1 = {0}', uid).
How to fetch friends, who are using app?
I can get all fields what i need, but for example for pictures i need to do additional requests. Can i get all needed fields in single request?
You can still use same FQL query with Graph API and JavaScript SDK
var query = 'SELECT uid, first_name, last_name, name, pic, pic_small, pic_big, birthday_date, sex, current_location, profile_url, is_app_user FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = ' + uid;
FB.api('/fql',{q:query}, function(response){
console.log(response.data);
});
You for sure can also get almost same data with Graph API not using FQL at all:
FB.api('/'+uid+'/friends', {
fields: 'id,first_name,last_name,name,birthday,gender,location,link,installed'
}, function(response){
console.log(response.data);
});
You have a bit different names and other format (ex location) for those details and miss the picture details in results but this is simple, user picture is available on URL in form http://graph.facebook.com/USER_ID/picture
use ?type=square | small | normal | large to request a different photo
I've been poking around with this too, using PHP. This is what I came up with:
$user_friends = $facebook->api('/me/friends?fields=installed');
$user_players = array();
foreach ($user_friends['data'] as $userfriend)
{
if (array_key_exists('installed', $userfriend))
{
array_push($user_players, $userfriend);
}
}
The Following Helps you to fetch user's friend details using graph api
NSString friendId =10020020 //Store Friend ID;
NSString * pRequestString = [NSString stringWithFormat:#"%#?fields=name,picture,work,hometown,birthday,devices,interests",friendId];
[[FBRequest requestForGraphPath:pRequestString ] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"%#",result);
}];

How can I replace 'me()' term in FQL iphone

I am creating an iphone app using Facebook api. Here I'm using the following query to get the friends details;
NSString* fql1 = [NSString stringWithFormat:#"SELECT uid,pic_square, name,online_presence FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY online_presence"];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
fql1, #"query",
nil];
[_facebook requestWithMethodName:#"fql.query" andParams:params andHttpMethod: #"POST" andDelegate: self];
here, I need to replace the term 'me()' to make my project running. So, how can I do that, I have my (user's) ID, name in hand. So will it work if I replace the term me() with user id, user name. If yes, how can I do that?
Please share your thoughts.
Thanks :)
Yes, just replace the 'me()' with the uid of the user you're looking for the info of
Indeed, you simply replace the me() with the uid.

How to get friends name in fql

I am executing this query in FQL [#"SELECT likes,message,actor_id FROM stream WHERE source_id = %lld limit 50", _session.uid]. It is giving result well but I want to fetch my friends name also. I don't want to execute query within loop to fetch friends name from their profile. If it is possible in multiquery then which type of query I will have to write?
I use this code:
NSString* fql = [NSString stringWithFormat:#"SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = %lld)", session.uid];
Hope it can give you a hint.