I am building an app that does the following:
- Grab Friends from Facebook
- Select 1-2 friends and add them to a group
I want users to be able to login with Facebook and have it look through all the groups and bring back any that their friends may be in. Each group is saved in Apigee with a 1-2 Facebook id properties.
I am not sure the best way to accomplish this.
Below is just what I did to at least give it a try. Obviously sending a request every time I loop through the friends is a horrible idea.
Help please?
http://apigee.com/docs/app-services/content/querying-your-app-services-data
function get_groups(){
//Stores array of friend ids
var friends = [];
//Request to Facebook and get friends
FB.api('/me/friends', 'GET', function(data){
for (i = 0; i < data.data.length; i++){
friends.push(data.data[i].id);
}
request(friends)
});
function request(friends){
for ( i = 0; i < friends.length ; i++) {
//Set ids to look for in the groups
var options = {
endpoint:"groups",
qs:{ql: "id1='" + friends[i] + "' or id2='" + friends[i] +"'"},
}
//Request to Apigee to query groups
client.request(options, function (err, data) {
if (err) {
console.log(err);
} else {
//do something with the data
}
});
}
}
}