Get Facebook friends attending an event? - iphone

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

Related

FQL for getting facebook user ids does not return "paging" key in response

Hi i want to get list of my fabebook friend ids with paging of 100 users.
The problem is that if i set hte FQL to
NSString *fqlString = #"SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) LIMIT 300";
It returns me as expected the only first 300 users in the table with out any reference to next page.
Result: {
data = (
{
uid = 1519xxx;
},
{
uid = 9806xxx;
}
....
);
}
if i request friends with [FBRequest requestForMyFriends] it returns me all of my friends and additionaly a paging key with the url object for next page.
The question is how can i tell with FQL to give me lists of 100 users with paging to next 100 users.
The Graph API returns paging links; FQL does not. So you’d have to do that yourself, by making another query including an OFFSET parameter.

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.

Facebook FQL - All fanpage Events a User is Attending

I am trying to achieve the following via Facebook's Multiquery FQL, get a list of all Fan Page Events that i am 'Attending'.
I have the below logic, and have tried to implement something similar with the FQL statement below.
get list of all events created by / from a Fan Page (using specific id)
get a list of all my (the users) events attending
Match eid's from event_member FQL Table
If they match ids, and rsvp_status is equal to attending
display result.
FQL Multi
{"query1":"SELECT eid FROM event WHERE
eid IN (SELECT eid FROM event_member
WHERE uid
=$fanpageID)","query2":"SELECT rsvp_status FROM event_member WHERE
uid = $uidAND eid IN
(SELECT eid FROM #query1)"}
I know the statement is incorrect, but i am struggling on trying to do this. I have achieved this via Graph API using a very messy set of foreach loops in my PHP code.
Using a single multiquery FQL statement would be far more efficient.
Any suggestions would be great.
EDIT
Problem im having now, is ifaour's FQL statement works within the FQL Query console (Returns Results), however when i run the following, and empty array is returned.
When i dissect the statement to just ( SELECT eid FROM event WHERE creator =$fanPageID) the FQL Console highlights that eid in non indexable.
Here is my PHP
function usersEventsPoints($uid,
$facebook, $fanpageID){
$events = "SELECT eid FROM event WHERE creator=$fanpageID AND eid
IN (SELECT eid FROM event_member WHERE
uid=$uid AND rsvp_status =
\"attending\")";
$eventsAttendance = $facebook->api(array(
'method' => 'fql.query',
'query' =>$events, ));
$eventsAttendingcount = 0;
foreach
($eventsAttendance as $eventsAttendanceFetch) {
if($eventsAttendanceFetch['eid'] == true){
$eventsAttendingcount++;
}
}
return $eventsAttendingcount;
}
Blockquote
Any Ideas?
It's a very simple task:
SELECT eid FROM event WHERE creator = $fanpageID AND eid IN (SELECT eid FROM event_member WHERE uid = me() AND rsvp_status = "attending")
This will return all events' Ids that are created/owned by the page that has $fanpageID id and you are a member in (me()) and your status is attending.
EDIT:
You are looping the returned array just to get the count?! you can simply use:
$eventsAttendingcount = count($eventsAttendance);
Also make sure that the user you are matching, has authorized your application and granted you the correct permission!
I'm not sure I understand what the problem is - I ran your FQL statement and it returns a list of events and then your RSVP status?
On another note, why not use the events.get method. You pass in the UserId and it will display the event information for you. You can filter by RSVP status.
Just checked and the events.get method is in the process of being deprecated.
You should use the new Graph API which gives you a list of attendees for your event:
http://developers.facebook.com/docs/reference/api/event
You get the list of attendees by using
https://graph.facebook.com/EVENT_ID/attending
If you want to get the next 10 events of the facebook logged user where events are set a attending then you can build your Swift query like this:
let graphPath = "/me/events?limit=10&type=attending&since=now"
let params = ["fields": "id, name, category, start_time, end_time, timezone, updated_time, type, attending_count, owner, place"]
let request = GraphRequest(graphPath: graphPath, parameters: params, accessToken: accessToken, httpMethod: .GET, apiVersion: apiVersion)
request.start {}