Can you make a user-based search with Facebook API? - facebook

On Facebook when you write something in the search box in the top.
Like 'Eric'
You first get the results with your friends named Eric and further down you get people you might know with X mutual friends and some random people in the vicinity you might know.
Is it possible to make a similar search with the Facebook API?
I've tried:
https://graph.facebook.com/search?q=eric&type=user&fields=id,name&access_token= (my token)
And thought if I added my access_token I would get a search like the one on Facebook. But I just get some random Eric's from all over the world.
I'm writing a simple web application and getting this search to work would be great! Thanks!

It's possible to an extent but before looking further ensure this isn't the main service of your app otherwise you run the risk of violating Facebook policy on replicating core functionality.
You need to look into the user FQL table and the friend table
Do an FQL call as follow:
SELECT name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())
Then save the JSON response from that call and use a typeahead algorithm / plugin.

Related

How to track the users have became fans of my facebook page?

I know there is a Facebook tool named insights, but, at the moment it does not give me the information I need.
I would like to create custom invitation code to track how many friend of a specific user have became the fans of my page.
Small example...
John becames fan of my page, I would like to undersand how many friends of John became fans of my page.
I do not know how to do that, but I must need to know how many users have become fans and by whom.
Is this possible with a Facebook page, or do I need to create an application?
Thank you!
This can be done with FQL (Facebook Query Language) using the Facebook Graph API. What you're looking for is the likes attribute which can be obtained from the JSON returned by http://graph.facebook.com/yourusername.
Ofcourse you will need to do further queries to obtain things like how many friends of a specific user liked your page. Probably something along the lines of SELECT ... FROM like WHERE object_id = yourpage and I would imagine you'd need to link that to the friend table with something like WHERE uid1 = friendid to get their friends.

How to use Facebook api to search for users

As the title says i want to search with Facebook Api (Graph Api or FQL, that doesnt matter, or even REST) for users.
For example: I want to search for "Britney Spears" and i want to get all users with that name (like %search%).
The result should be like http://www.facebook.com/search/results.php?q=britney%20spears&init=quick&tas=0.8058435615324403&type=users
you can use the search API from the Graph API for a particular user like this:
People: https://graph.facebook.com/search?q=USER_NAME&type=user
If you want to search for a list of users, you can you this:
SELECT uid, username, name, pic_square FROM user WHERE contains("Joe Biden")
Refer official user table docs to see all the fields you can query
But the CONTAINS() function is known to be mysterious and no one from facebook has clarified it yet. It might work in some cases and others it might not.
see thread: Documentation for CONTAINS() in FQL?
I guess the final answer would be that you cannot replicate the facebook search functionality like the site does (searching all users of a given name). You can only search users related to the current logged in user who is using your app since these are the type of social apps that facebook wants developers to build. They want you building apps that provide value to their users by utilizing their social graph of their friends and relatives. Developers don't need site wise search for this I suppose, hence there is no API to do this (yet).

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 to find top friends on facebook

I am trying to develop an application on facebook for which i need those friends with whom the user interacts the most on facebook .In short i need a list of top friends of a user. How can i do that.What parameters do i need to look for in the graph api for finding the top friends.
Facebook doesn't provide this information directly per se but it would be pretty easy to use FQL statements to generate this information yourself. Check out the FQL documentation asn you could run queries against the stream table to find user interactions. You could also look at checkin table and album/photo/photo_tag, although these would require more permissions from the user.

How would I get a list of 'friends' who have added my Facebook application?

I'm really struggling with something that should be a simple matter: Showing a user of my Facebook app a list of their friends also using the app. Is there nothing built into the APIs to allow such a common request?
The only thing I can think of to do is to get the list of the user's friends, and then get all the users from my database who are in that list, and then fetch information for each of those facebook ids. But that seems an extremely roundabout way of doing things...
The only way I've found to do this is to use FQL and a previously documented, but now undocumented field:
SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=<user's uid>) AND is_app_user=1 ORDER BY name
The undocumented field is the user.is_app_user, which is listed in the old documentation wiki but not in the shiny new docs. No idea if this means it'll be removed in the future, but there doesn't seem to be any other way to get this data with the new Graph API.
Just in-case you're still using the old REST API, you can also call the friends.getAppUsers method.
You can actually use Facebook's old REST API to do this by sending a GET request to: https://api.facebook.com/method/friends.getAppUsers
If you need JSON data back, then add the parameter format=json
You need an access token to do this. See the documentation here:
http://developers.facebook.com/docs/reference/rest/friends.getAppUsers/