Say a user updates their email on their Facebook.com, will that new email address be synced to my drupal site user's profile? What about the rest of the profile fields? Not that I expect a user's birthday or gender to change all that often haha. More concerned about their email address, location, etc.

Sorry if I missed this in the documentation, my understanding is that it currently only passes the info you want to collect the very first time the user connects.

Comments

quicksketch’s picture

my understanding is that it currently only passes the info you want to collect the very first time the user connects.

That is correct. Right now we don't even provide a hook to fire every time a user logs in, but I'd be happy to add such a hook if you're interested.

"Syncing" information is extremely messy though, as users could easily change their Drupal e-mail to something else than their Facebook e-mail, and automatically replacing their manual information with their Facebook e-mail on every login could be quite annoying. You'd need to somehow keep track of when users updated information both in Drupal and Facebook, and use the latest one only if they hadn't modified their local one. But since Facebook doesn't provide that information, I'm not sure how you could handle it. The whole situation would be a lot of trouble.

grasmash’s picture

I would find a login hook very useful. I'm currently using hook_fboauth_actions_alter() to override the 'connect' callback in order to fire additional functions.

grasmash’s picture

@quicksketch

I'd be willing to help implement this hook with a little bit of advice. Would you suggest simply adding module_invoke_all() to a number of the control structures in fboauth_action_connect() ? Haven't done much work creating my own hooks, so I thought I'd check before rolling a patch.

E.g.,

function fboauth_action_connect($app_id, $access_token) {
  global $user;
  $fbuser = fboauth_graph_query('me', $access_token);

  if (isset($fbuser->id)) { 
    $uid = fboauth_uid_load($fbuser->id);
    // If the user has logged in before, load their account and login.
    if (!$user->uid && $uid && ($account = user_load($uid))) {
      fboauth_login_user($account);
    }
    // If the Facebook e-mail address matches an existing account, bind them
    // together and log in as that account.
    elseif (!empty($fbuser->email) && ($account = array_shift(user_load_multiple(array(), array('mail' => $fbuser->email))))) {
      fboauth_save($account->uid, $fbuser->id);
      // Logins will be denied if the user's account is blocked.
      if (fboauth_login_user($account)) {
        drupal_set_message(t('You\'ve connected your account with Facebook.'));
        // TRIGGER HOOK.
        module_invoke_all('fboauth_connect');
      }
    }
    else {
      // If the user is already logged in, associate the two accounts.
      if ($user->uid) {
        // TRIGGER HOOK.
        module_invoke_all('fboauth_connect');
      
        fboauth_save($user->uid, $fbuser->id);
        drupal_set_message(t('You\'ve connected your account with Facebook.'));
      }
      // Register a new user only if allowed.
      elseif (variable_get('user_register', 1)) {
        $account = fboauth_create_user($fbuser);
        // Load the account fresh just to have a fully-loaded object.
        $account = user_load($account->uid);
      
        // TRIGGER HOOK.
        module_invoke_all('fboauth_connect');
            
        // If the account requires administrator approval the new account will
        // have a status of '0' and not be activated yet.
        if ($account->status == 0) {
          _user_mail_notify('register_pending_approval', $account);
          drupal_set_message(t('An account has been created for you on @sitename but an administrator needs to approve your account. In the meantime, a welcome message with further instructions has been sent to your e-mail address.', array('@sitename' => variable_get('site_name', ''))));
        }
        // Log in the user if no approval is required.
        elseif (fboauth_login_user($account)) {
          drupal_set_message(t('Welcome to @sitename. Basic information has been imported from Facebook into your account. You may want to <a href="!edit">edit your account</a> to confirm the details and set a password.', array('@sitename' => variable_get('site_name', ''), '!edit' => url('user/' . $account->uid . '/edit'))));
        }
        // If the login fails, fboauth_login_user() throws its own error message.
      }
      // Since user's can't create new accounts on their own, show an error.
      else {
        drupal_set_message('Your Facebook e-mail address does not match any existing accounts. If you have an account, you must first log in before you can connect your account to Facebook. Creation of new accounts on this site is disabled.');
      }
    }
  }
}

quicksketch’s picture

We already have a hook inside of fboauth_create_user() (hook_fboauth_user_presave()), I think we just need to add a module_invoke_all() inside of fboauth_login_user(), perhaps passing $fbuser into fboauth_login_user() so that it can pass it forward to the hook. The only downside of this approach is that it doesn't fire a hook when binding a Facebook user with an existing Drupal account. I'm not sure how important that is at this point.

gkdreamz’s picture

Assigned: Unassigned » gkdreamz
Priority: Normal » Major

is there any way to get friends education history and work history.i tried to send permission friend_education_histroy and friend_work-history on fboauth.fboauth.inc file.but i got an error.how will i pass the permission to facebook and get my friend info.Any help would be greatly appreciated, Thanks.

gkdreamz’s picture

Priority: Major » Critical
quicksketch’s picture

Priority: Critical » Normal
Status: Active » Closed (fixed)

is there any way to get friends education history and work history.i tried to send permission friend_education_histroy and friend_work-history

This question is unrelated to the topic of this issue (which has been answered already). I don't provide support on custom coding, but you can read the official documentation of Facebook permissions here: https://developers.facebook.com/docs/reference/login/

In short. There isn't a way to get access to friend's personal information, since that would almost certainly violate privacy. The user has to grant access to their own information (though "basic information" is always available about a user's friends).

Brian E. Conklin’s picture

I've been searching and trying different things for a couple of days now and still haven't found a resolution. I need to be able to update drupal's info on a user from Facebook. This is the case in the change of a piece of FB data but also when I add a field in Drupal to fill from FB. If they've already connected, it must be manually entered instead of pulling it from FB.

I tried disconnecting a user from FB and then reconnecting but I don't get any of their FB data on the reconnection.

How can I implement a "refresh" of FB data either by button click or login or can we have Drupal repull all FB data on a disconnect/reconnect evolution?

jhm’s picture