Using flags with DFB
vssaokar - February 9, 2009 - 05:54
| Project: | Drupal for Facebook |
| Version: | 6.x-2.x-dev |
| Component: | Miscellaneous |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
I am trying to use flags module with Drupal for facebook. I want to display only nodes that are flagged by facebook friends of current user. Flag module provides only "Any User" and "Current User" as filter options for "Is Flagged By" in the view. I would like "Is Flagged By" -> "Facebook friend" as an option.
Any ideas how I can do this? I am fine with modifying the php code. Need some directions on what needs to change.
Thanks in advance!

#1
writing argument and filter handlers for views is failry involved. You can find reasonable doc for it on drupal.org. Look at fb_views.module for an example. It defines an argument handler which limits a view to nodes authored by friends of the given user.
If you get it working, please post the code here. It might help others define similar filters.
#2
I made the change to flag views code to handle this. There are some issues and I need to debug.
Question: how do I see the db queries when running the app thru facebook? I have enabled Devel module.
#3
I just tried enabling the devel query log, and it appears fine on canvas pages as well as regular pages. Is that what you're talking about?
#4
That is right. I see the queries in regular pages and not on canvas pages. I have enabled devel query log. Any ideas?
#5
When you view the canvas pages, you're probably a user without permission to view devel info. Try letting all users (anon and registered) see devel info.
#6
Excellent! That did it. thanks.
#7
Dave,
I modified the flag.views.inc to add the filter code. But I am getting the following SQL error,
Unknown column 'fb_user_app.fbu' in 'where clause' query: pager_query SELECT count(node.nid) FROM node node LEFT JOIN flag_content flag_content_recommendmovie ON node.nid = flag_content_recommendmovie.content_id AND flag_content_recommendmovie.fid = '2' LEFT JOIN flag_content flag_content_recommendmovie2 ON node.nid = flag_content_recommendmovie2.content_id LEFT JOIN users flag_users_recommendmovie ON flag_content_recommendmovie.uid = flag_users_recommendmovie.uid WHERE (node.status = '1') AND (flag_content_recommendmovie.uid IS NOT NULL) AND (fb_user_app.fbu IN (1229240,500082917,508457230,518038926,533871278,540043831,541288400,552380769,560771745,585053032,592421364,592597736,603769327,613170792,625116962,628460171,637250521,641933284,642386762,643723853,645496843,647012462,649222115,657949364,670921669,671761112,684362532,688395307,692991684,694089967,697816227,706755587,709846800,710893008,727800851,728955437,737754310,776357989,1035296673,1064457289,1067418725,1204913164,1233981813,1424152757,1477177102,1507380422)) AND (node.nid = 488) in /home/9a0440c5/web/public/includes/database.mysql.inc on line 174.
I am attaching the flag.views.inc code. For some reason, fb_user_app is not getting added to the join.
Any ideas?
#8
ITs a matter of getting views to add fb_user_fbu to the join clauses. I'm not expert enough to tell you exactly how. Coding for views is tricky.
#9
I made change to flag views code to handle this. Attached is the code for anybody interested.
Example Usage : "Recommend Movie" flag on CCK type "Movie". View to show only your facebook friends who recommend this movie. In the flag filter section, " 'Is Flagged By' has this additional option now - 'Facebook User: Author is Friend'
#10
extending drupal for facebook fb_friends using drupal flag_friends ...
i build a function that flag all facebook friends that have added the application as drupal 'friends':
function _moodboard_flag_fbfriends($uid) {global $fb, $fb_app;
$fbu = _fb_user_get_fbu($uid,$fb_app);
if ($fbu) {
$flag = flag_get_flag('friend');
#$friends = flag_friend_get_friends($uid); // $friends[$uid]
// Get list of friends who have authorized this app.
$rs = $fb->api_client->fql_query("SELECT uid FROM user WHERE has_added_app=1 AND uid IN (SELECT uid2 FROM friend WHERE uid1 = $fbu)");
if (isset($rs) && is_array($rs)) {
foreach ($rs as $friend_data) {
$friend_fbu = $friend_data['uid'];
$account = fb_user_get_local_user($friend_fbu, $GLOBALS['fb_app']);
if ($account->uid) {
$fuid = $account->uid;
$status = flag_friend_determine_friend_status($flag, $uid, $fuid);
if ($status == FLAG_FRIEND_UNFLAGGED) {
db_query("INSERT INTO {flag_friend} VALUES(%d, %d, %d)", $uid, $fuid, $_SERVER['REQUEST_TIME']);
}
}
}
}
}
}
to check if a user has new appz friends you call:
_moodboard_flag_fbfriends($user->uid);More info or troubleshooting: