Community Documentation

Is the current user logged into facebook?

Last updated March 19, 2013. Created by Dave Cohen on November 11, 2010.
Log in to edit this page.

fb_facebook_user()

fb.module provides a method, fb_facebook_user(), which returns the user's ID on facebook. It will return a positive integer if a) the user is logged into facebook and b) has authorized your application. In other words, if they are connected this function returns their ID.

<?php
if ($fbu = fb_facebook_user()) {
 
// The user is connected to facebook and $fbu is their ID.
}
else {
 
// The user is ether not logged into facebook or has not authorized the application.
}
?>

fb_get_fbu()

fb.module also provides fb_get_fbu(), which will tell you whether a local drupal account is connected to a facebook account. This will return a facebook user id regardless of whether the user is currently logged into drupal of facebook.

<?php
if ($fbu = fb_get_fbu(42)) {
 
// The local user with uid == 42 is mapped to a facebook ID ($fbu).
}
else {
 
// The local user with uid == 42 is not connected to facebook.
}
?>

About this page

Drupal version
Drupal 6.x
Audience
Programmers

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here