function fb_user_get_local_friends in Drupal for Facebook 7.3
Same name and namespace in other branches
- 5.2 fb_user.module \fb_user_get_local_friends()
- 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()
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.
Only works if the "map accounts" feature is enabled.
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 1168 - This module manages relations between local Drupal user accounts and their accounts on facebook.com.
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)) {
$result = db_select('fb_user', 'fb')
->fields('fb', array(
'uid',
))
->condition('fb.fbu', $fbus, 'IN')
->execute();
foreach ($result as $data) {
if ($data->uid) {
$uids[] = $data->uid;
}
}
}
return $uids;
}