Getting Facebook friends' locations is time consuming
In this algorithm I am looping through each friend to find their location, yet this is very inefficient... for 100 friends, this script takes over 2 minutes...can anyone suggest a more efficient solution?
开发者_高级运维@friends[1..100].each do |f| # 'f' contains basic friend info (name, uid) friend = get_friend(f['id']) # 'friend' gets data for each friend if friend.has_key?('location') @friends_locations[friend['name']] = friend['location']['name'] end end
Im using Koala API and Ruby on Rails... thanks!
Try FQL instead u can query/queries by post it throught REST API too the query would be so ething like
select ... From user where hid in (select uid2 from friends where uid1 = me())
You can send 20 queries at a time using Batch Requests. But FQL is probably a better approach and I haven't heard that it is deprecated.
精彩评论