Search code examples
ruby-on-railsfacebookfacebook-graph-apifb-graph

How to make batch request using fb_graph?


when a user login using facebook then i need collect all the movies list liked by the user and his/her friends.

 user = FbGraph::User.fetch('me', :access_token => "access_token")
 userFrnd = user.friends
 movies=[]
 userFrnd.each do | uf |
  frnd = FbGraph::User.fetch(uf.raw_attributes['id'], :access_token => "access_token")
  movies << frnd.movies
 end
 final_movie_list = movies.flatten.uniq_by {|track| track.raw_attributes["id"]}

this is my fb_graph function and it's working fine.but i need to make it as batch request since the i have 360 friend it take 360 request to process the above function correctly.but help me out to optimize this and reduce the time it takes to calculate this function. I came to know that batch request may help me but,i don't know how to do that in fb_graph. Please help me


Solution

  • I'm using FbGraph from ( github.com/nov/fb_graph ) Version: 2.7.8 and I'm able to make a batch request for 100 users, at a time and get following information about them by default. I'm not using any access token. So you might be able to get more information including movies.

    • id
    • name
    • first_name
    • last_name
    • link
    • username
    • gender
    • locale

    Here's the demonstration code where ids is an array of Facebook User Ids:

     r = FbGraph::User.fetch("?ids=#{ids.join(",")}")
     r.raw_attributes  #information about the users hashed by their id (String)