In my own twitter login implementation I have it set up in such a way that once the user has been authenticated and (saved and) loaded, it retrieves the picture from Twitter, resizes it, saves it and updates the user picture path in the database. it depends on imageAPI, but this is only out of laziness :)

You could add the following to the end of twitter_signin_oauth_callback_submit()

$sourceUrl = $response['profile_image_url'];
$goalPathOriginal = file_directory_path()."/user_pictures/picture-".$response->screen_name."-original.jpg";
$goalPathResized = file_directory_path()."/user_pictures/picture-".$response->screen_name.".jpg";
$USER_PICTURE_WIDTH = 73;
$USER_PICTURE_HEIGHT = 73;

if ($account) {
  try {
    //if imageapi module exists
    if (module_exists("imageapi")) {
      //copy user picture from twitter
      file_save_data(file_get_contents($sourceUrl), $goalPathOriginal, FILE_EXISTS_REPLACE);
			
      //resize picture to 73x73 and save
      $image = imageapi_image_open($goalPathOriginal);
      imageapi_image_resize($image, $USER_PICTURE_WIDTH, $USER_PICTURE_HEIGHT);
      imageapi_image_close($image, $goalPathResized);
      $edit = array (
        'picture' => $goalPathResized
      );
      user_save($account, $edit);
    }			
  } catch (Exception $e) {
    watchdog('oauth_login', "Error saving/handling user picture: ".$e->getMessage(),'',WATCHDOG_WARNING);
  }
}

Some issues:
- It assumes a directory user_pictures exists in the files directory
- It assumes the picture is jpeg (probably not valid)

Sorry, I have no experiences with patches, so I don't know how to wrap it up properly. Hope this helps though.
Eelke

CommentFileSizeAuthor
#4 twitter.signin.import.image_.patch1.39 KBmchelen

Comments

youkho’s picture

Just tested doesn't seem to work for me.

eelkeboezeman’s picture

what's the error?

DrupalKing’s picture

I tried this code and when a user logins for first time with twitter (and do drupal tries to make it an account), I get this error:

user warning: Duplicate entry '' for key 'name' query: INSERT INTO users (created) VALUES (1273513247) in /home/wdwtoday/public_html/wdwtodayreunion/modules/user/user.module on line 327.

mchelen’s picture

StatusFileSize
new1.39 KB

Getting about the same error:

user warning: Duplicate entry '' for key 2 query: INSERT INTO users (created) VALUES (1274169276) in /home/mikechelen/drupal-6.16/modules/user/user.module on line 327.

Patch is attached if anyone else wants to try (made from root module directory). Support for .GIF and .PNG would be great too.

greg.harvey’s picture

@Mike, is this the same patch you posted in #771882: Sub-module for showing Twitter avatars with Drupal profiles - include in the main Twitter package?? It looks like the sub-module there might solve the problem, for now at least. Unless the maintainers of the Twitter module want to incorporate this feature. They haven't commented in any related threads I've found, so I'm guessing it's pretty far off their radar.

steinmb’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

InTheLyonsDen’s picture

Title: Import user image from Twitter upon login » Has anyone ported this to D7?
Version: 6.x-3.x-dev » 7.x-3.x-dev

I am stuck on a project and looking at RPX / Janrain as an alternative unless I can find a work around for D7. Any success?

Thanks!
Kevin

greg.harvey’s picture

Title: Has anyone ported this to D7? » Import user image from Twitter upon login
Version: 7.x-3.x-dev » 6.x-3.x-dev
blackspiraldancer’s picture

Status: Closed (fixed) » Active

Same error here as the others.
Could you take a look into this? I prefer this approach over than the plain "just display the picture" http://drupal.org/node/771882 but the database insert error make this code unusable.

xurizaemon’s picture

Status: Active » Closed (duplicate)

Dupe of #771882: Sub-module for showing Twitter avatars with Drupal profiles - include in the main Twitter package?. Closing this one; if the other gets some action and becomes a full module then perhaps it can have the code to pull local copies of the files down added.