tanda raho
2008-May-06 16:37 UTC
[Facebooker-talk] check_friendship method only returning value of last pair
Hello, I''m new to facebooker and ruby, so not sure if the issue I am having is due to my misunderstanding or a bug in facebooker plugin. Here is what I have: def show @current_user ||= facebook_session.user @member ||= params[:id].to_s==@current_user.id.to_s ? @current_user : Facebooker::User.new(params[:id]) #for each of current_user''s friends, check if they are friends with the member and return an array of only the mutual friends @mutual_friends = [] #initializing array to store mutual friends #create an array in the format of [[friend1ID,memberID],[friend2ID,memberID]...] @friends_array = @current_user.friends.map {|friend| [friend.id, at member.id]} #submit that array to check_friendship and store the resultant hash, which should have format {[friend1ID,memberID]=>true,[friend2ID,memberID]=>false} @friends_hash = facebook_session.check_friendship(@friends_array) # for each value in the returned hash, store the friendID if value is true @friends_hash.each {|key,value| @mutual_friends << key[0] if value} end Looking at check_friendship method, the hash returned should have the same size as the array passed in. But the hash being returned (@friends_hash) always only has size of 1. Is this happening because of the code in check_friendship I commented below? # File lib/facebooker/session.rb, line 218 def check_friendship(array_of_pairs_of_users) uids1 = [] uids2 = [] array_of_pairs_of_users.each do |pair| uids1 = pair.first ############ should this be uids1 << pair.first ############## uids2 = pair.last ############ should this be uids2 << pair.last ############## end post(''facebook.friends.areFriends'', :uids1 => uids1, :uids2 => uids2) end I tried to change the uid assignment to << rather than = in session.rb, but it is raising an IncorrectSignature error which I couldn''t track down how to fix/override. Any help would be appreciated! Thanks!
tanda raho
2008-May-08 08:00 UTC
[Facebooker-talk] check_friendship method only returning value of last pair
Ok, I think I fixed the problem with check_friendship not actually using all the array data passed to it and only sending Facebook the last friend combination. I had to add a couple of lines to convert the arrays to comma delimited strings as per the facebook API. Perhaps there are more efficient ways of making these changes, so any suggestions are welcome. I''m new to ruby/rails/facebooker, so not sure how it works to submit bug reports/patches for this gem/plugin. If anyone can point me to the instructions, I would be more than glad to try and get the patch through. I had to change check_friendship() in lib/facebooker/session.rb to the following: def check_friendship(array_of_pairs_of_users) uids1 = [] uids2 = [] array_of_pairs_of_users.each do |pair| uids1 << pair.first #CHANGED = to << uids2 << pair.last #CHANGED = to << end uids1 = uids1.join('','') # ADDED THIS LINE uids2 = uids2.join('','') # ADDED THIS LINE post(''facebook.friends.areFriends'', :uids1 => uids1, :uids2 => uids2) end Thanks! On Tue, May 6, 2008 at 9:37 AM, tanda raho <tandaraho at gmail.com> wrote:> Hello, I''m new to facebooker and ruby, so not sure if the issue I am > having is due to my misunderstanding or a bug in facebooker plugin. > Here is what I have: > > def show > @current_user ||= facebook_session.user > @member ||= params[:id].to_s==@current_user.id.to_s ? > @current_user : Facebooker::User.new(params[:id]) > > #for each of current_user''s friends, check if they are friends > with the member and return an array of only the mutual friends > @mutual_friends = [] #initializing array to store mutual friends > > #create an array in the format of > [[friend1ID,memberID],[friend2ID,memberID]...] > @friends_array = @current_user.friends.map {|friend| > [friend.id, at member.id]} > > #submit that array to check_friendship and store the resultant > hash, which should have format > {[friend1ID,memberID]=>true,[friend2ID,memberID]=>false} > @friends_hash = facebook_session.check_friendship(@friends_array) > > # for each value in the returned hash, store the friendID if value is true > @friends_hash.each {|key,value| @mutual_friends << key[0] if value} > end > > Looking at check_friendship method, the hash returned should have the > same size as the array passed in. But the hash being returned > (@friends_hash) always only has size of 1. > > Is this happening because of the code in check_friendship I commented below? > > # File lib/facebooker/session.rb, line 218 > def check_friendship(array_of_pairs_of_users) > uids1 = [] > uids2 = [] > array_of_pairs_of_users.each do |pair| > uids1 = pair.first ############ should this be uids1 << > pair.first ############## > uids2 = pair.last ############ should this be uids2 << > pair.last ############## > end > post(''facebook.friends.areFriends'', :uids1 => uids1, :uids2 => uids2) > end > > I tried to change the uid assignment to << rather than = in > session.rb, but it is raising an IncorrectSignature error which I > couldn''t track down how to fix/override. > > Any help would be appreciated! > > Thanks! >