开发者

Rails, Facebook API, Koala gem — get all profiles of users who 'Like' a page

Using Rails3 and koala gem, how to retrive all profiles of users who 'Like' a F开发者_Go百科B 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.

Thanks!


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.

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"]

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜