Hash 访问考拉朋友连接返回的数据

Hash 访问考拉朋友连接返回的数据,hash,koala,Hash,Koala,因此,我试图获取用户使用考拉的朋友的姓名: @graph = Koala::Facebook::API.new(self.authentication_token) @graph.get_connections("me", "friends").each do |friend| puts friend['name'] end 但是,这将显示整个哈希,ala: {"name"=>"Tad Luedtke", "id"

因此,我试图获取用户使用考拉的朋友的姓名:

        @graph = Koala::Facebook::API.new(self.authentication_token)
        @graph.get_connections("me", "friends").each do |friend|
            puts friend['name']
        end 
但是,这将显示整个哈希,ala:

{"name"=>"Tad Luedtke", "id"=>"17212478"}, {"name"=>"Harrison Hoffman", "id"=>"17212694"}, {"name"=>"Greg Nelson", "id"=>"17212720"}

我做错了什么?

我认为您在控制台中这样做是正确的吗?尝试向上滚动。在代码块执行完毕后,它会输出整个哈希值,如果您有几个以上的朋友,这个哈希值非常大,因此您必须向上滚动才能看到puts语句。我只是在rails控制台中完成了这项工作

如果您正在使用rails控制台并希望禁用它(关闭IRB),请尝试以下命令

conf.echo = false

然后运行您的代码。

您需要首先将这些散列转换为数组,您只需尝试这些代码即可

@graph = Koala::Facebook::API.new(self.authentication_token)
@friends =@graph.get_connections("me", "friends").to_a
@friends.each do |friend|
puts friend["name"]
end 

我看不出问题所在,相同的代码返回了我的朋友列表。