function fb_user_get_local_friends in Drupal for Facebook 5.2
Same name and namespace in other branches
- 5 fb_user.module \fb_user_get_local_friends()
- 6.3 fb_user.module \fb_user_get_local_friends()
- 6.2 fb_user.module \fb_user_get_local_friends()
- 7.3 fb_user.module \fb_user_get_local_friends()
Returns local uids of friends of a given user.
Query is relatively efficient for the current user of a canvas page. For all other users, and non-canvas pages it requires expensive call to facebook. That said, our local database query may be inefficient for users with large numbers of friends, so use with caution.
TODO: should this function cache results?
Note: the api takes fbu as a parameter, but this usually causes problems because facebook restricts users to query only about their own friends. For the time being, expect this function to work only on canvas pages to find friends of the current user.
1 call to fb_user_get_local_friends()
- fb_devel_fbu_page in ./
fb_devel.module - A page which tests function which work with facebook user ids
File
- ./
fb_user.module, line 791 - This module allows Drupal user records to be associated with Facebook user ids. It can create local user accounts when Facebook users visit an application's canvas pages.
Code
function fb_user_get_local_friends($fbu = NULL, $fb_app = NULL) {
if (!isset($fbu)) {
$fbu = fb_facebook_user();
}
$uids = array();
if ($fbus = fb_get_friends($fbu, $fb_app)) {
// Should this query be limited to users of the app?
$query = "SELECT uid FROM {fb_user_app} WHERE fbu in (%s)";
$args[] = implode(',', $fbus);
$result = db_query($query, $args);
while ($data = db_fetch_object($result)) {
if ($data->uid) {
$uids[] = $data->uid;
}
}
}
return $uids;
}