I enabled the Facebook Connect component of this module suite and set it to automatically create accounts for Facebook users (which bypasses the User Registration page). It works well, but up to a point. It does create the account, import the user's picture from Facebook, and redirect to the user-edit screen. However, at this point there are several usability issues:

  1. The module does not import the user's email address from Facebook, which means that the Email Address field is blank. This is the case both on the user-edit screen and in the {users} table in the database. We should be able to access the user's address via Facebook Connect, as long as the user agrees to let our app access their personal information, right?
  2. On the same topic-- this is more along the lines of a 'feature request'-- is it possible to map Facebook fields (such as first/last name) to profile fields in Drupal? This is far less critical but I thought I'd mention it.
  3. When an account is automatically created, Drupal sets a default password. Not having set that password, though, the new user would have no idea what their password is, which is a problem when related to the first item above, because in order to set/change their email address in Drupal 7, a user has to type their password. It seems to me (if it's possible within Drupal) to remove the whole password issue completely for Drupal users who signed up through Facebook Connect, since these users, when they return to your site, will log back in using FB Connect rather than typing a username/password. Is it possible to remove password fields entirely for FB Connect users, which would let them connect to the site and edit their profiles without having to retype a password?

Comments

imoreno’s picture

Hi nateeanes,
Regarding #1
you will have to enable the extended permission module and ask for the "Email - send me emails (email)" permission. once you will do that when a user will approve your application upon login you will have access to his email details.

BR
Itzhak

visuaLatte’s picture

Thanks! That helps. Do you have any idea about #3-- is it possible to use Drupal without a password if you're authenticated through a 3rd-party service like Facebook?

Mackee’s picture

The same thing that I need to do. On the drupal for facebook site tour, you can just edit your account and change password.

Mackee’s picture

Problem was solved, if someone might encounter this check out: http://drupal.org/project/nocurrent_pass

Dave Cohen’s picture

I haven't really investigated this. My feeling is that drupal core should not prompt for the old password when the user has none.

In the meantime that other module looks like a promising workaround.

skchan2’s picture

did you guys ever figure out #2?

I'm trying to create a user registration form that can prefill fields like first and last name, if the user logs in with FB.

Dave Cohen’s picture

Category: bug » feature

I'm trying to create a user registration form that can prefill fields like first and last name, if the user logs in with FB.

fb_user.module will do that for name and email fields. Use that code as an example for your custom fields.

It would be great to have a module that somehow adds another option to drupal fields. Something like "get default value from facebook". And their choose which facebook graph path maps to the field path. Really the difficulty is mapping what on facebook corresponds to what on facebook. In practice, I make a snippet of code to do this custom each time and just haven't taken the time to make a module do it in a generic way.

skchan2’s picture

I enabled the user module and the fb_user.module will prefill the username and email (after logging in to fb on the "Create Account" page, the username and email field arent prefilled until i refresh the page)

are there any step by step instructions on creating the snippet to prefill custom fields and where it should go?

Thanks for your help on this.

skchan2’s picture

Any place I can get in depth instructions? the documentation on drupalforfacebook.org doesn't help.

jlea9378’s picture

Did you figure out how to get other profile fields and store them in Drupal? I see an example in the links Dave referenced but I can't get them to work. I have the following but it isn't working when I create a new account or update an existing one, but FB Devel shows that the data should be available.

function fosteru_fb_user($op, $data, &$return) {
  global $user;
  dsm(dprint_r($data));
  if($op == FB_USER_OP_PRE_USER) {
    $return['field_name_first']['und'][0]['value'] = $data['info']['first_name'];
    $return['field_name_last']['und'][0]['value'] = $data['info']['last_name'];
	$return['field_facebook_url']['und'][0]['value'] = $data['info']['link'];
  }
}

The drupal_set_message call never shows, and the data doesn't get stored in the profile.

Dave Cohen’s picture

Try letting both anonymous and authenticated users view devel messages, then the dsm() may appear. Or use watchdog() instead.

jlea9378’s picture

Oh ok. Thanks. Do you see any problems with my code or know why it won't work?

jlea9378’s picture

I'm still having troubles figuring this out. This is what I have now:

function fosteru_fb_user($op, $data, &$return) {
  global $user;

  //dpm($op);
  //watchdog("fosteru", $op);

  if($op == "post_external_login") {
	$fosteru_fb = fb_api('me');

    $user->field_name_first['und'][0]['value'] = $fosteru_fb['first_name'];
    $user->field_name_last['und'][0]['value'] = $fosteru_fb['last_name'];
	$user->field_facebook_url['und'][0]['url'] = $fosteru_fb['link'];
  }
}

The dpm($op) call shows that the op is post_external_login. But my attempts to update the user's account fields don't work. Can anyone help?

Dave Cohen’s picture

That code when op is post_external_login may be changing the global user, but it wouldn't have any lasting effect. Maybe user_save() afterward would.

When op is FB_USER_OP_PRE_USER, the account hasn't been created yet, so any changes made will be saved for you.

jlea9378’s picture

From what I could tell during my experimentation, the function was never called during user registration. My site is set up so that users go through registration manually.

I'll try user save and see how that works. Thanks.

jlea9378’s picture

The following code worked for me:

function fosteru_fb_user($op, $data, &$return) {
  global $user;
  $account = user_load($user->uid);
  $edit = array();

  //devel_print_object($user);
  //dpm($op);
  //watchdog("fosteru", $op);

  if($op == "post_external_login") {
	$fosteru_fb = fb_api('me');
	//devel_print_object($fosteru_fb);
    $edit['field_name_first']['und'][0]['value'] = $fosteru_fb['first_name'];
    $edit['field_name_last']['und'][0]['value'] = $fosteru_fb['last_name'];
	$edit['field_facebook_url']['und'][0]['url'] = $fosteru_fb['link'];

	user_save($account, $edit);
  }
}

Thanks for your help!