Menu

#1 add Google contact photo

Unstable (example)
open-invalid
nobody
None
5
2011-12-21
2011-12-21
No

Adding some code before the $CONTACTS->insert($a_record,false) would get the google picture of the contact:
// start photo
$photoLink = (object) $entry->getLink('http://schemas.google.com/contacts/2008/rel#photo');
if ( !empty($photoLink) and !empty($photoLink->extensionAttributes) ) {
$photo = $gdata->get($photoLink->getHref()); // fetch image
$a_record['photoetag'] = $photo->getHeader('ETag');
$a_record['photo'] = $photo->getBody(); // we have a jpg image
}
// end photo

hth Markus Neubauer

Discussion

  • Markus Neubauer

    Markus Neubauer - 2011-12-21
    • status: open --> open-works-for-me
     
  • Les

    Les - 2011-12-21

    I have tried your suggested code however, it has some serious problems. I would love to help debug this but I don't completely understand the how the photos work.

    The problem that I have seen with this is that it only loads some of the contacts, not all of them and there are many error messages about getting a 404 when expecting a 200.

    I would suggest that you have some of your google contacts with photos and some with out and then get that to work. Remember that you must log out of roundcube, then log back in and go look at the contacts to see your changes.

     
  • Les

    Les - 2011-12-21
    • status: open-works-for-me --> open-invalid
     
  • Les

    Les - 2011-12-21

    This is a nice start but has a bug. On my installation I tried this and when i first go to the google contacts. I get many errors stating that it got 404 and expected 200. Then when I go to click on any contact, NONE of them will load and throw an error.

    I did examine the mysql database table and i do see that you have actually retrieved photo images. But, due to catching an exception just below your code, none of the data is usable.

    Also I noticed that I only get about half of my contacts to load with this code in place.

    So there it seems there is some situation at google that will cause this code to crash not allowing to finish loading.

    The line that is causing the error is this one...

    $photo = $gdata->get($photoLink->getHref()); // fetch image

     
  • Les

    Les - 2011-12-21

    Sorry for all the responses on this but I have been doing some debugging. Since you seem to understand the photo portion of this, maybe you can find the answer.

    when using a different google account, your mod works perfectly!

    After doing some debugging with my main google account, where it fails, I have determined that it was failing on any record that has a broken image.

    Specifically, if I go to google contacts on the google site, I see a broken image where the image is suppose to be. I don't know how this is possible. I had 3 records like this and after clicking the broken image and either replacing the image or saying "No Image" the problem has gone away.

    So some error handling needs to happen where you can detect this BEFORE calling this line...

    $photo = $gdata->get($photoLink->getHref()); // fetch image

    That is the line causing the crash. If you had a way to know that the photo was missing before calling it, your mod would be perfect.

     
  • Markus Neubauer

    Markus Neubauer - 2011-12-22

    As I dont have any failures i could look at the strgucture.
    Could you put some code in the file and send me the dump vars right before the getHref:
    ...
    mn_dump($photoLink);
    $photo = $gdata->get($photoLink->getHref()); // fetch image
    ...

    // MN DEBUG
    // trace some vars on debug request
    function mn_dump( $v ) {
    $mnhandle = fopen("temp/mn_dump_var_export.tmp", 'a');
    fwrite ( $mnhandle , "\n" . var_export($v,true) . "\n" );
    fclose( $mnhandle );
    }
    // MN DEBUG

    I'm interesseted in the last one, the one that failed.
    Thanks Markus

     
  • Les

    Les - 2011-12-22

    I am unable to reproduce this as I already corrected the 3 google contacts entries that had the bad images. I have not found a way to put back an invalid image. This may have been a google bug.

    I have released the new 2.11 version which has your code in it. I have a lot of users that use my RC installation so I will monitor the logs to see if it happens to anyone else.

     
  • Markus Neubauer

    Markus Neubauer - 2011-12-22

    The real problem. that i have is: Id like to store the etag and photoetag in a real db file to improve the sync process any for photos id need the photoetag to make updates on the pic.
    Any idea to fill things with live?
    ALTER TABLE `google_contacts` ADD `etag` VARCHAR( 48 ) NOT NULL;
    ALTER TABLE `google_contacts` ADD `photoetag` VARCHAR( 48 ) NOT NULL;

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.