Hi,

First of all, thanks for that great module.

I have some questions :

  • How can I map the FB user picture to the Drupal avatar?
  • Is there a way to use the FB name for Drupal username (the mapping doesn't work and it seems it is hard-coded in _connector_create_account() ?

Thanks in advance

Laurent

CommentFileSizeAuthor
#5 connector-user_save_hook-1503278-5.patch531 bytesbburg

Comments

voxpelli’s picture

Facebook names aren't unique - how would you be able to use them as usernames? Usernames has to be unique? You can use them when presenting users - but behind the scenes new users will have to be given unique usernames - right?

agence web coheractio’s picture

You are right. I didn't notice that.
What about avatars ? Can we feed them into Drupal's user picture ?

agence web coheractio’s picture

For those who are interested.

It seems that FB user picture can't be retrieved through query parameter hence it can't be mapped in the connector (if this is possible, please let me know).

However, you can fetch it with the following code taken from fboauth.module

  // Taken from fboauth.fboauth.inc
  if ($user->uid && variable_get('user_pictures', 0)) {
    $picture_directory =  file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures');
    if(file_prepare_directory($picture_directory, FILE_CREATE_DIRECTORY)){
      $picture_result = drupal_http_request('https://graph.facebook.com/' . $remote_id . '/picture?type=large');
      $picture_path = file_stream_wrapper_uri_normalize($picture_directory . '/picture-' . $user->uid . '-' . REQUEST_TIME . '.jpg');
      $picture_file = file_save_data($picture_result->data, $picture_path, FILE_EXISTS_REPLACE);

      // Check to make sure the picture isn't too large for the site settings.
      $max_dimensions = variable_get('user_picture_dimensions', '85x85');
      file_validate_image_resolution($picture_file, $max_dimensions);

      // Update the user record.
      $picture_file->uid = $user->uid;
      $picture_file = file_save($picture_file);
      file_usage_add($picture_file, 'user', 'user', $user->uid);
      db_update('users')
        ->fields(array(
        'picture' => $picture_file->fid,
        ))
        ->condition('uid', $user->uid)
        ->execute();
    }
  }

Laurent

frans’s picture

See also
http://drupal.org/node/1450664
And the patch that is used there.

We try standardization for fields, but it is not so easy.

The profile image from FB is not a real endpoint, it redirects to the image itself. That makes it even worse.

bburg’s picture

StatusFileSize
new531 bytes

Instead of trying to standardize how these fields are saved, I propose invoking a hook after user_save in _connector_create_account() to allow other modules to manipulate the user, in the way they require, while we still have the provider data available.

Immediately after the user is created:

module_invoke_all('connector_create_account_insert', $new_account, $info, $connector_name);

Patch for 7.x-1.0-beta2

socialnicheguru’s picture

Issue summary: View changes
Status: Active » Needs review