Fetch friends data with Graph API - facebook

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);
}];

Related

Get Female Friends facebook

I want to get female friends facebook
$fql = "https://graph.facebook.com/me/fql?q=SELECT sex, uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND sex = 'female' LIMIT 10&access_token=$access_token";
$fqlresult = file_get_contents($fql);
$f = json_decode($fqlresult, true);
$friends1 = $f['data']['1']['uid'];
I tried this but not returning anything.
You can try using graph api to get friends gender and filter using php code to get female friends:
$query = "https://graph.facebook.com/v2.1/me?fields=friends{gender,name}&acess_token=$your_access_token";
$results = file_get_contents($query);
$freinds = json_decode($results , true);
foreach($freinds as $friend)
{
if($friend['gender']=='female')
{
echo $friend['name'].'<br>';
}
}
The FQL query SELECT sex, uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND sex = 'female' LIMIT 10
is correct and works (I tried it), your overall API query needs to be something like
https://graph.facebook.com/fql?q=
not
https://graph.facebook.com/me/fql?q=
remove me

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

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.

FQL to get Online Friends return zero

I am trying to get Online Friends by using following code.
protected void GetActiveFriends()
{
var fb = new FacebookWebClient();
dynamic myInfo = fb.Get("me");
var uId = myInfo.id;
dynamic friends = fb.Query("SELECT uid, name, pic_small, online_presence FROM user WHERE online_presence IN ('active', 'idle') AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())");
Response.Write(friends.Count);
foreach (dynamic friend in friends)
{
Response.Write(friend.id);
}
}
friends.Count returns Zero & none of the friend.id gets displayed.
I guess my query is right then what's the problem.
Never mind got it. Had not added extra permissions.