在Facebook上通过rFacebook获得Ruby的朋友年龄 [英] Get age of friend on Facebook with Ruby via rFacebook

查看:123
本文介绍了在Facebook上通过rFacebook获得Ruby的朋友年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Facebook应用,需要访问人们的年龄 - 只有用户的朋友,而不是公众。

I am creating a Facebook app and need to access people's ages - only the friends of the user, not the general public.

我正在使用rFacebook版本0.6。 2,沿着这个

I am using rFacebook version 0.6.2, setup along the line of this.

我需要获得所有朋友的年龄/生日。

I need to get the ages/ birthdays of all of my friends.

推荐答案

根据 http://rfacebook.rubyforge。 org / rFacebook不被维护,它建议Facebooker,但即使Facebooker还没有更新几个月: https ://github.com/mmangino/facebooker

As per http://rfacebook.rubyforge.org/ rFacebook isnt being maintained, it suggested Facebooker, but even Facebooker hasn't been updated in months: https://github.com/mmangino/facebooker

我建议考拉(而不只是因为我是澳大利亚人)。阅读: https://github.com/arsduo/koala 还有关于设置Koala的详细信息on Rails: https://github.com/arsduo/koala/wiki/Koala- on-Rails

I suggest Koala (and not just because I'm an Aussie). Have a read at: https://github.com/arsduo/koala There's also details on setting Koala up on Rails: https://github.com/arsduo/koala/wiki/Koala-on-Rails

我刚刚使用考拉和自定义标签页构建了一个FB应用程序,这非常快速。

I just built a FB app using Koala and a Custom Tab Page last week and it was very quick.

您还需要阅读: http://developers.facebook.com/ docs / authentication / (注意提及范围和权限级别)。根据: http://developers.facebook.com/docs/authentication/permissions/请求您的范围时,您必须要求friends_birthday。

You also need to read: http://developers.facebook.com/docs/authentication/ (pay attention to the mention of scopes and permission levels). As per: http://developers.facebook.com/docs/authentication/permissions/ you must request 'friends_birthday' when you request your scope.

我不知道有没有一个简单的方式让你的所有朋友的生日一批。您可能必须遍历每个朋友并获取他们的信息。

I'm not sure there is an easy way to get all your friends' birthdays in a batch. You might have to traverse each friend and get their info.

作为测试,请转到: http://developers.facebook.com/docs/reference/api/ ,然后点击朋友链接。然后复制你的第一个朋友的ID。在URL中,使用您复制的ID替换'/ me / friends'。例如: https://graph.facebook.com/me/friends?access_token=ABC123成为 https://graph.facebook.com/12345678?access_token=ABC123 您然后会看到该朋友的数据,其中一个字段是生日。

As a test, go to: http://developers.facebook.com/docs/reference/api/ and click on the friends link. Then copy the ID of your first friend. In the URL replace '/me/friends' with the ID you copied. Eg: https://graph.facebook.com/me/friends?access_token=ABC123 becomes https://graph.facebook.com/12345678?access_token=ABC123 You will then see the data of that friend, one field of which is birthday.

#i have already asked for user permissions, and have my access token
#https://github.com/arsduo/koala/wiki/OAuth
graph = Koala::Facebook::GraphAPI.new(oauth_access_token)
friends = graph.get_connections("me", "friends")
friends.each do |f|
   friend = graph.get_object(f['id'])
   puts "#{f['name']} has a birthday on #{friend["birthday"]}"
end

尽管您可能可以使用FQL来执行批处理。

Although, you might be able to use FQL to do a batch.

#FQL taken from http://stackoverflow.com/questions/5063431/easiest-way-to-get-birthday-info-of-all-friends-thorugh-graph-api 
fql = "select uid,name,birthday_date from user where uid in (select uid2 from friend where uid1=me())"
#https://github.com/arsduo/koala/wiki/REST-API
@rest = Koala::Facebook::GraphAndRestAPI.new(oauth_access_token)
birthdays = @rest.fql_query(fql)

祝你好运!

这篇关于在Facebook上通过rFacebook获得Ruby的朋友年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆