Reputation: 11
In Facebook's search bar I can enter phrases like "My friends who play Soccer" and get a list of results. How can I do that with Facebook's API ? Should I use Graph API or Open Graph API ? I tried using the graph API explorer but it didn't work so well for me. I'm not even sure what's the right query to use or which permissions are necessary for retrieving this kind of data. Any ideas ?
Upvotes: 1
Views: 404
Reputation: 959
You can do this a couple of different ways.
First option would be to add filters so the user can say I am looking for people, places, pages, etc. where they define the type of search and then whatever they type you send that query.
The second option which is probably what I would use. The user types and you make your call to each type of search and then you show them in whatever priority you like.
You should only have to register a facebook app and then use that api key for all your queries. It is only going to give you access to public information unless you are given permission by users to search their private information.
Here is a link on how to structure the query: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search
Structure looks like
GET graph.facebook.com/search?q={your-query}&[type={object-type}](#searchtypes)
So calls would looks something like this:
GET graph.facebook.com/search?q="Bruce Lee"&type=user
What I mentioned before that I would do is this, someone types John Lance soccer
You would send all of these queries and sort the results:
GET graph.facebook.com/search?q="John Lance soccer"&type=user
GET graph.facebook.com/search?q="John Lance soccer"&type=page
GET graph.facebook.com/search?q="John Lance soccer"&type=event
GET graph.facebook.com/search?q="John Lance soccer"&type=group
Facebook is going to now give you back similar results that they show for their search. I don't know if this is the best way to do it, but it is one way.
********************UPDATE*********************
For you to search friends in v2 both the user and the friend have to grant your app access. This was switched in v2.
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/friends
Upvotes: 0
Reputation: 74014
You can´t do that with the Facebook API. The Search API is pretty limited, mostly for privacy reasons, i assume: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search
Upvotes: 0