[Facebooker-talk] Friendship and cie

Stéphane Akkaoui stephane.akkaoui at imeuble.info
Sat Nov 1 09:30:21 EDT 2008


Hi,

I was adding a new feature in Facebooker : mutual_friends_between. A  
good usage could be to find mutual friends between a user_id and a  
logged in user :

	fb_session.mutual_friends_between(519798494, current_user)

Of course, this method rely on the check_friendship method and the  
implementation in the parser of `facebook.friends.areFriends` API call.

I wanted to know why does the parser sort ids when building the array  
of hashes ?

         memo[[Integer(hash['uid1']), Integer(hash['uid2'])].sort] =  
are_friends?(hash['are_friends'])
												^^^^
It result that depending of the ids (which are totaly unpredictable),  
we are given with a randomly ordered list...
For exemple, if facebook returns me :

	<friends_areFriends_response xmlns="http://api.facebook.com/1.0/"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
	instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd 
" list="true">
	  <friend_info>
	    <uid1>105925</uid1>
	    <uid2>785637999</uid2>
	    <are_friends>0</are_friends>
	  </friend_info>
	  <friend_info>
	    <uid1>506773312</uid1>
	    <uid2>785637999</uid2>
	    <are_friends>0</are_friends>
	  </friend_info>
	  <friend_info>
	    <uid1>508625501</uid1>
	    <uid2>785637999</uid2>
	    <are_friends>0</are_friends>
	  </friend_info>
	  <friend_info>
	    <uid1>1233961883</uid1>
	    <uid2>785637999</uid2>
	    <are_friends>1</are_friends>
	  </friend_info>
	  <friend_info>
	    <uid1>1119061733</uid1>
	    <uid2>785637999</uid2>
	    <are_friends>0</are_friends>
	  </friend_info>
	</friends_areFriends_response>

It will result :
	
	{[508625501, 785637999]=>false,[785637999, 1119061733]=>false,  
[105925, 785637999]=>false,[506773312,
   	785637999]=>false,[785637999, 1233961883]=>true}

Here, uid2 is sometimes the first sometimes the second element even if  
Facebook return it always at the same place.
It would be better to have it the same way facebook give it to us :

	{[508625501, 785637999]=>false,[1119061733, 785637999]=>false,  
[105925, 785637999]=>false,[506773312,
	785637999]=>false,[1233961883, 785637999]=>true}

So unless there is a good reason that i miss, i strongly suggest not  
to sort ids.
What do you think ?

In the same time, I have fixed the check_friendships method to allow  
it to compare multiple couples of ids.
I think we should change tests to take unordered ids and improve the  
mock to take care of arguments.

All this is commited in my fork of the facebooker git repository :  
git://github.com/meuble/facebooker.git

-- 
Stéphane Akkaoui
http://www.sociabliz.com (fr)
http://www.imeuble.info (fr)


More information about the Facebooker-talk mailing list