1

I am building an app that does the following:

  1. Grab Friends from Facebook
  2. 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
            }   
        });     
      }
   }
}
ekad
  • 14,436
  • 26
  • 44
  • 46
leylandjacob
  • 201
  • 2
  • 5

2 Answers2

0

I think you can use the querying concept defined here: http://apigee.com/docs/app-services/content/querying-your-data

Apart from that i believe whatever you are trying now is the best way. Because i don't know of any way to fetch all the entities in the group in a single call and compare the data within the entity(in this case the facebook id).

[would also like to learn if there is any other way]

0

You can explore the option of entity relation ships based on Groups and see if this can be simplified http://apigee.com/docs/app-services/content/entity-relationships

randomness
  • 1,377
  • 1
  • 14
  • 21