Reputation: 257
I'm trying to implement a search bar in an iOS app that searches through a user's friends and displays results. I don't want to have to get all users using https://graph.facebook.com/me/friends and then searching through the results. Is it possible to add a query to such a call (e.g. https://graph.facebook.com/me/friends?q=TIM)? Using the search function of the graph API seems to only search publicly.
Upvotes: 1
Views: 5003
Reputation: 96413
You can do it using FQL:
SELECT uid, username, first_name, last_name FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = me()) AND first_name = 'tim'
Although, there’s no explicit wildcard search possible, no LIKE operator supported. But you can fake that using the strpos
function.
Upvotes: 1
Reputation: 5021
As you can see at the Graph API Explorer, you can't search the list of friends via Graph API, https://developers.facebook.com/tools/explorer?method=GET&path=me/friends?q=Philip
You can simple get a list with all the friends,
and then in the for
loop you use to print the results, you can search for a username/or id.
a simple example:
FB.api('/me/friends/', function(response) {
if (response) {
for (var i=0, l=response.data.length; i<l; i++) {
var friend = response.data[i];
if(friend.name === 'Philip') {
alert('Philip Found!');
}
}
}
});
Upvotes: 1