Rails,Facebook API,Koala gem —获取“喜欢"页面的用户的所有个人资料 [英] Rails, Facebook API, Koala gem — get all profiles of users who 'Like' a page
问题描述
使用Rails3和无尾熊gem,如何检索喜欢" FB页面的用户的所有个人资料(例如,http://facebook.com/DAKINE).有可能吗? 作为最终结果,我需要获取一堆存储在db中的用户配置文件.
Using Rails3 and koala gem, how to retrive all profiles of users who 'Like' a FB page (http://facebook.com/DAKINE for example). Is it possible at all? As the final result i need to get a bunch of user profiles, stored in db.
谢谢!
推荐答案
在Facebook上获取任何页面的喜欢都非常容易,尤其是使用Koala宝石时.由于给定页面的Facebook点赞可以公开访问(请参阅此处),因此您无需访问即可访问它们使用API密钥.
It's pretty easy to get the likes of any page on facebook, particularly with the Koala gem. Since the facebook likes for a given page are publically accessible (see here), you can access them without using an API key.
例如,要获得该页面的顶数: facebook.com/foofighters ,您可以这样做:
For example, to obtain the number of likes for this page: facebook.com/foofighters you could do:
graph = Koala::Facebook::GraphAPI.new
likes = graph.get_object("foofighters")["likes"]
我假设您已将用户配置文件存储在应用程序数据库中,并且其中的每个(或某些)都有关联的Facebook ID?如果您要为用户本地保存喜欢"数据,则可以执行以下操作:
I'm assuming you have your user profiles stored in your application database, and each (or some) of these have associated facebook IDs? If you're trying to save the 'like' data locally for your users, you could do something along the lines of:
graph = Koala::Facebook::GraphAPI.new
@users.each do |user|
user.likes = graph.get_object(user.facebook_id)["likes"]
user.save
end
这篇关于Rails,Facebook API,Koala gem —获取“喜欢"页面的用户的所有个人资料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!