使用 fb_graph Ruby gem 从 Facebook 检索好友位置

发布于 2024-11-04 17:12:42 字数 861 浏览 1 评论 0原文

我正在尝试使用 gem 检索用户所有朋友的位置:fb_graph。 (版本 1.7.2)

我的权限是:publish_stream、read_friendlists、offline_access、friends_location、user_location

我已经对用户进行了身份验证并存储了离线访问令牌及其 Facebook ID。

user = User.find_by_email("[email protected]")
facebook_user = FbGraph::User.fetch(user.facebook_identifier, :access_token => user.facebook_access_token)
facebook_user.friends.map(&:location) => [nil, nil...]

当我检查 Facebook 内部的权限时,它说我可以访问好友位置:

http://grab.by/a1Qm

我的问题是,当我尝试获取朋友的位置时,它总是返回零。我已经正确设置了权限,并且我知道该位置对于每个人来说都不应该为零。

有人对如何获取朋友位置有任何建议或指示吗?

谢谢!

I'm trying to retrieve the locations of all of a user's friends using the gem: fb_graph. (version 1.7.2)

My permissions are: publish_stream,read_friendlists,offline_access,friends_location,user_location

I've already authenticated the user and stored the offline access token and their facebook id.

user = User.find_by_email("[email protected]")
facebook_user = FbGraph::User.fetch(user.facebook_identifier, :access_token => user.facebook_access_token)
facebook_user.friends.map(&:location) => [nil, nil...]

When I check the permissions from within Facebook it says I have access to friend locations:

http://grab.by/a1Qm

My problem is when I try and get the locations of my friends it always returns nil. I have permissions setup correctly and I know the location should not be nil for everybody.

Does anybody have any suggestions or pointers on how to go about getting friend locations?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半枫 2024-11-11 17:12:43

API 权限不会覆盖用户的隐私设置。您的 Facebook 用户隐私设置是否可能阻止此操作?或者也许您所有朋友的隐私设置都阻止了此操作?

API permissions do not override a user's privacy settings. Is it possible that your facebook user privacy settings block this? Or perhaps all of your friends' privacy settings block this?

冬天旳寂寞 2024-11-11 17:12:42

所以我能够获得我需要的信息。您必须在每次调用后调用 fetch ,因此

user = User.find_by_email("[email protected]")

facebook_user = FbGraph::User.fetch(user.facebook_identifier, :access_token => user.facebook_access_token)
friends = facebook_user.fetch.friends
friends.each do |friend|
  location = friend.fetch.location
  puts location.try(:name)
end

这会获取我想要的数据,但是迭代所有内容并对每条数据进行单独调用的速度相当慢,因此我重构为仅使用直接 FQL 返回我需要的所有数据。

friend_data = FbGraph::Query.new("SELECT uid, first_name, last_name, pic_square, current_location FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1='#{user.facebook_identifier}')").fetch(user.facebook_access_token)

So I as able to get the information I needed. You have to call fetch after each call, so

user = User.find_by_email("[email protected]")

facebook_user = FbGraph::User.fetch(user.facebook_identifier, :access_token => user.facebook_access_token)
friends = facebook_user.fetch.friends
friends.each do |friend|
  location = friend.fetch.location
  puts location.try(:name)
end

This gets me the data that I want, however it is rather slow iterating over everything and doing an individual call for each piece of data so I refactored to just use straight FQL to return all the data that I needed.

friend_data = FbGraph::Query.new("SELECT uid, first_name, last_name, pic_square, current_location FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1='#{user.facebook_identifier}')").fetch(user.facebook_access_token)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文