After instantiating a connection to the Graph API, I can do this:

@graph.get_connections("me", "friends")

This returns a list of friends containing their name and id.

If I wanted more info from these friends, I can do:

@graph.get_connections("me", "friends").each do |f|
    fdetails = get_object(f['id'])
    # do stuff
end

But this way I will have to make as many requests to the Graph API as the number of friends!

Is there something that would give me the fields I want from each user from the initial call?

In short, how do I do this?

@graph.get_connections("me", "friends", :fields => "image,bio")
有帮助吗?

解决方案

You can try this in your controller :

 graph  = Koala::Facebook::API.new(session[:token])
          user = graph.get_object("me")
          @friends = graph.get_connections(user["id"], "friends?fields=id,name,link")
session[:token] : contain my token

and in your view for example :

    <% @friends.each do |f| %>
<%= link_to f["name"], f["link"], :target => '_blank'%>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top