使用fb_graph Ruby宝石从Facebook获取朋友的位置 [英] Retrieve friends locations from Facebook using fb_graph Ruby gem
问题描述
我正在使用宝石检索所有用户的朋友的位置: fb_graph 。 (版本1.7.2)
我的权限是: publish_stream,read_friendlists,offline_access,friends_location,user_location
我已经验证了用户,并存储了离线访问令牌和他们的Facebook ID。
user = User.find_by_email(person@email.com)
facebook_user = FbGraph :: User.fetch(user.facebook_identifier,:access_token => user.facebook_access_token)
facebook_user.friends.map(& :位置)=> [nil,nil ...]
当我检查Facebook内的权限时,表示我有权限到朋友的位置:
我的问题是当我尝试并获得我的朋友的位置总是返回nil。我有正确的权限设置,我知道每个人的位置不应该是零。
有没有人有任何关于如何获得朋友位置的建议或指针? p>
谢谢!
所以我能够得到我需要的信息。每次通话后,您必须致电 fetch ,因此
user = User.find_by_email(email @ domain.com)
facebook_user = FbGraph :: User.fetch(user.facebook_identifier,:access_token => user.facebook_access_token)
friends = facebook_user.fetch.friends
朋友
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)
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("person@email.com")
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:
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!
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@domain.com")
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)
这篇关于使用fb_graph Ruby宝石从Facebook获取朋友的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!