Get friends attending to an event - facebook

I searched in the documentation and in the web and didn't find anything about this.
So, when you go to an event page on facebook the list of people who are attending to the event seems to be ordered putting your friends in first place. I want to do that but I can't figure out how.
If I make:
https://graph.facebook.com/<event_id>/attending
I get all people who are attending and it seems it is ordered by when the person clicked on 'attending'.
If I make:
https://graph.facebook.com/<event_id>/attending/<user_id>/friends
I get all friends of the user regardless if they are attending to the event or not.
I tried a lot of connections using Graph API Explorer (https://developers.facebook.com/tools/explorer) like getting the friends of the user and then trying to match them with that event, but could'nt find the solution.
Any help? Thanks in advance.

Better to use FQL in this case. More suited to this type of nested question.
select uid, rsvp_status from event_member where eid = <EVENT_ID> and uid IN (SELECT uid2 from friend where uid1 = me())
That will return all friends of the person logged in who are attending the event you specify.

The accepted answer doesn't work anymore, as facebook no longer allows event attendee requests without one of the event admins' access keys (see Graph api reference). As they also removed the option to access friends' events for privacy reasons, there is currently no way of doing this solely via the Graph API

Related

Some facebook friends' birthdays returning as null but I have the correct API permissions

I'm tring to get my friends' birthdays in my app and some of them are null. I thought that those people don't have a birthday set, but they actually do.
My fql query is:
SELECT uid,name,birthday_date FROM user WHERE uid IN (SELECT uid2 from friend where uid1=me())
The birthdays are also null when I request /me/friends?fields=birthday
My access token has the friends_birthday permission set.
I also tried with birthday instead of birthday_date in the FQL query. Same result.
I imagine that this happens because they opted out somehow, but I don't know how.
Is there an alternate solution to actually get their birthdays from facebook?
It's also possible to remove the ability of apps to access your data when your friends use them, this option will prevent the current session user from seeing some information about their friends via the API, even if that information is accessible on Facebook.com
This setting is in the privacy settings, at https://www.facebook.com/settings/?tab=privacy, under Ads, Apps and Websites -> 'How people bring your info to apps they use' and looks like this:
{edit} you can test this for yourself with test users, it's the most likely reason assuming the birthdays are visible to you in the frontend
These people might have set their Birthdays visible to only themselves or only some restricted friends. This is an option available if we try to edit our Birthday by its side. That can cause it is not available to your query by app.

Facebook FQL or graph API events

I'm trying to develop an application wich will get all the facebook events and show it on a iphone application.
My question is what is the best way to retrieve all the public facebook events in PHP. I know there is the FQL and the open graph api but with FQL I cannot retrieve just all the public events and I can't seem to find a way to do this.
Can somebody help me with this ?
Kind regards !
Both FQL and the Graph Api work well. Both are great options.
FQL:
FQL may be faster if you want to get all the events from all a user's
friends.
FQL has a method of getting the count of attendees, maybes,
not attendings, and "no replies" directly, without having to count
yourself, which saves LOTS of time when dealing with 20,000 people
concerts etc. [ IF you want to calculate the gender ratios,
unfortunately then this feature wont help you much ]
FQL has a method of determining who was invited by whom, called "inviter" from the "event_member" table, though it appears to be presently broken: Finding who INVITED you :: Facebook FQL Explorer Bug: "Inviter":null
If you are using FQL, you can use "privacy" to determine if the event is public.
SELECT name, venue, location, start_time FROM event WHERE eid in
(SELECT eid FROM event_member WHERE uid=me())
The Graph:
- You used to check "privacy" for the privacy of an event. It is now depreciated and I believe it doesn't matter now, because only the events you have access to will show up.
$JSON = $facebook->api('/'.$target.'/events?fields=name,venue,location,start_time,description,picture.type(large),attending.fields(gender)&since='.time());
TIP: IF your program should show events for one specific region, can use an app's authentication rather than nag a user to log in and approve your app ( unless you have special customizations for each user).

How to get friends in order of number of mutual friends?

I am developing a Facebook application. I want to know how I can get friends in the order of number of mutual friends.
Is it possible with FQL or any other method?
Update
I can't find a way to do it in one request using graph API
but it can be done in Ruby by getting friends list then sending request for each friend using User context like this example
Original answer
Here is the FQL query to be used Which is working only for api versions < v2.1
SELECT uid, mutual_friend_count from user where uid in (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY mutual_friend_count desc
you can try it in the explorer
https://developers.facebook.com/tools/explorer?method=GET&path=fql%3Fq%3DSELECT%20uid%2C%20mutual_friend_count%2C%20friend_count%20from%20user%20where%20uid%20in%20%28SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%3Dme%28%29%29%20ORDER%20BY%20mutual_friend_count%20desc
Theoretically, you can get a list of a user's friends using:
$friendsOfFriend = $facebook->api('/'.$yourFriendsFacebookId.'/friends');
Then you can check each of the result to see if they are your friend too.
$isMyFriend = $facebook->api('/me/friends/'.$someonesFacebookId);
... and keep a track of the count.
However my test didn't return any result yet. I attempted to get the friends of some of my facebook friends but it returns an exception: Can't lookup all friends of {friend's_facebook_ID}. Can only lookup for the logged in user {my_facebook_ID}, or friends of the logged in user with the appropriate permission. So there might be permission issue here.
I don't think mutual friends are available via FQL so you would have to do this the hard: calling the graph api in a loop for each friend and getting a count of mutual friends. The graph api method is: /me/mutualfriends/yourFriendsId and you could do 20 batch requests at a time to help speed this up. If you can find a way to do this with FQL, that would be your fastest route.
This is only a partial answer as they are not all in one place, still haven't found a way to get them on one page yet, but it is a start, could be run in a loop programmatically through your friend list...
https://www.facebook.com/browse/mutual_friends/?uid=xxxxxxxxxxxx
because if you don't give a uid it returns an error... I was just trying to get a list of all my friends on one pagem, but no dice. ridonculous.

How can I determine which friends of the currently logged in user are also using my app?

The Graph API makes it easy for me to determine who the friends of the current user are. I have two questions:
Is it possible, using the Graph API, to determine the list of users for the currently authenticated application?
Is it possible to determine the friends of the current user who are also users of my application (the intersection of my app's users and the current user's friends)? Is this possible using FQL?
No, This is not possible. Refer to this answer.
There's a rest method called friends.getAppUsers for this. Or you could use FQL:
SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) AND is_app_user=1

Getting friends of friends in FB graph API

I would like to get friends of friends via an API call and when I try to do it, I get the following exception,
{
"error": {
"type": "OAuthException",
"message": "(#604) Can't lookup all friends of .... Can only lookup for the logged in user (...), or friends of the logged in user with the appropriate permission"
}
}
The URL I am trying to access is,
https://graph.facebook.com/friend_id/friends?access_token=access_token
I am getting extended permissions which is as follows,
<fb:login-button perms="user_likes,friends_likes"></fb:login-button>
Could any one please let me know what's going wrong here? Or does it mean I can never get access to friends of friends?
Currently, there is no extended permission that allows you to view a user's friends of friends. The "*_likes" permissions just show you the Facebook pages that the users have Liked.
It might be possible for you to iteratively fetch and cache the friends of each of the user's friends, one by one, but without access tokens for each friend, you'll only be able to fetch public data.
I got friends of friends(limited). I had same problem. Though it is very late for answering question, it will help somebody. That's why answering this question.
We can get friends of friends those are app users.
$fb_id= user id whose friends of friends required.
$query="SELECT uid, name, work_history FROM user WHERE uid IN (SELECT
uid2 FROM friend WHERE uid1 IN (SELECT uid FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = $fb_id ) and is_app_user=1) )";
$user_info=$facebook->api(array('method'=>'fql.query',
'query'=>$query));
#Olie:
You are fetching your friends of your friend through application. So you would need permission from your friend whose friends you want. i.e. Your friend should be using that application and accepted those permission while allowing accessing information. Otherwise you wont be able to friends of your friend. I have tested this query. And it works successfully.
"message": "(#604) Can't lookup all friends of .... Can only lookup for the logged in user (...), or friends of the logged in user with the appropriate permission"
This message explains well. Read carefully.
Hope you understand solution criteria.
You cannot get friends of friends, it is not allowed due to privacy concerns.
A workaround we have done before is to save all users friends to oure own database.
That way we could cross-reference all the different users friend-list's and at least get friends of friends who have used the application we made.
Important note, such a table would quickly grow quite seizable depending on the amount of users you get.
Count on each user having about 250-300 friends on average, so if you opt for such a solution make sure to optimize your database for it, and then it should work just great.
Got same problem, had to use old REST API to get at least mutual friends, see
http://developers.facebook.com/docs/reference/rest/friends.getMutualFriends/
You can get the friends of the current user through a Graph API call to me/friends. You will need any valid access_token, no special extended permissions, just the Basic one. There is one caveat, that user must allow you to see their friend list. So in the Privacy Settings > Connecting on Facebook there is a "See your friend list" setting. If the user has chosen a custom setting and selected say "Only Me" you will get this error.
Similarly, if the current user allows others to see their friend list, but one of the friends shuts this down due to privacy concerns then you will not be able to see any data and will get that error.
I was able to verify the scenarios I have described.
Unfortunately, I can't ask your answer specifically since I don't have experience with the FB API. However, I believe that FB allows users to hide who their friends are. If they have this set, then perhaps you won't be able to access their friends at all. I'd try to modify your code to first check what the permissions of a given user are and only then accessing their friends list if you have access to it. A bit of speculation here, though.