ay-fb-friend-rank (demonstration) is a PHP 5.3 class that can calculate who are the best user's friends. Data accuracy depends on the user activity and granted permissions. The only dependancy is Facebook PHP SDK.
All the data is collected in two batched requests. Nonetheless, it takes time for Facebook to prepare this data (sometimes up to 5 seconds). Therefore, you are advised to cache the data once you have it and repeat the query only if user has approved more permissions.
Follow the blog entry about the Facebook Friend Rank Algorithm to find out about possible implementations.
The following steps are taken to calculate the user ranking:
-
The applications looks through user's feed entries.
read_streampermission is required. However, if the latter is not given the app will rely on the public feed.- Profile is given
feed_likescore for liking user's feed . - Profile is given
feed_commentscore for leaving a comment on user's feed. - Profile is given
feed_addressedscore for addressing user in his feed, whether by posting directly on his wall or tagging the user in his post.
- Profile is given
-
Photos.
user_photosandfriends_photospermissions are required.- Profile is given
photo_tagged_user_by_friendscore if he tagged user in a photo. - Profile is given
photo_tagged_friend_by_userscore if user tagged him in a photo. - Profile is given
photo_likescore for liking a picture either uploaded by the user or a photo where user is tagged. - Profile is given
photo_commentscore for leaving a comment on a picture either uploaded by the user or a photo where user is tagged.
- Profile is given
-
Friends. No additional permissions required.
- Profile is given
friend_mutualscore for every mutual friend.
- Profile is given
-
Inbox.
read_mailboxis required.- Every profile is given
inbox_in_conversationfor participating in a mutual conversation with the user. inbox_chatscore is given for every message in a duologue.
- Every profile is given
By default every action is valued 1. Every criteria can be assigned an individual weight using setCriteriaWeight([action name, see $criteria], [numeric value]) method.
- There are many more permissions that can improve the friend-rank accuracy that the script doesn't utilise yet, eg.
user_hometown,friends_hometown,user_interests,friends_interests. - As per Jeff Widman's thoughts on the EdgeRank (http://edgerank.net/), this script dramatically lacks Time Decay criteria. This is the next thing on the to-do-list.
This class will become redundant once Facebook makes communication_rank column publicly available.
SELECT uid2, communication_rank FROM friend where uid1 = me() ORDER BY communication_rank DESC LIMIT 10;
A similar attempt to calculate the friend index has been made by Mike Jarema using Ruby.
The BSD License - Copyright (c) 2012 Gajus Kuizinas.