Можем ли мы получить изображение для (как минимум) контактов Gmail, найденных в списке контактов пользователя?

В настоящее время я получаю электронную почту и имя, например:

function tratar_gmail($accesstoken){
    $max_results = 3000;
    $url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&oauth_token='.$accesstoken;
    //echo $url;
    $xmlresponse =  curl_file_get_contents($url);
    if((strlen(stristr($xmlresponse,'Authorization required'))>0) && (strlen(stristr($xmlresponse,'Error '))>0))
    {
        echo "<h2>OOPS !! Something went wrong. Please try reloading the page.</h2>";
        exit();
    }
    $xml =  new SimpleXMLElement($xmlresponse);
    $xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
    $result = $xml->xpath('//gd:email');
    $return;

    foreach ($result as $title) {

      $parts = explode('@', $title->attributes()->address);


      $pos = count($return);
      $return[$pos]['email'] = $title->attributes()->address;
      $return[$pos]['name'] = strip_tags($parts[0]);
    }

куда $title отвалов:

object(SimpleXMLElement)#4 (1) {   ["@attributes"]=>   array(3) {     ["rel"]=>     string(38) "http://schemas.google.com/g/2005#other"     ["address"]=>     string(18) "xxxxxxx@wanadoo.es"     ["primary"]=>     string(4) "true"   } }

Но было бы здорово получить некоторые изображения, по крайней мере, для контактов Gmail, есть ли способ?

что-то вроде:

$return[$pos]['email'] = $title->attributes()->address;
$return[$pos]['name'] = strip_tags($parts[0]);
if (preg_match('/^gmail.com/', $return[$pos]['emal']) {
     $return[$pos]['pic'] = magic_goes_here()
}

1 ответ

Ссылка на фото находится в контактной записи:

<entry xmlns='http://www.w3.org/2005/Atom'
    xmlns:gContact='http://schemas.google.com/contact/2008'
    xmlns:gd='http://schemas.google.com/g/2005'
    gd:etag='{contactEtag}'>
  <id>
    http://www.google.com/m8/feeds/contacts/{userEmail}/base/{contactId}
  </id>
  ...
  <link rel='http://schemas.google.com/contacts/2008/rel#photo' type='image/*'
    href='https://www.google.com/m8/feeds/photos/media/{userEmail}/{contactId}'
    gd:etag='{photoEtag}'/>

Если нет фото, то link элемент не будет иметь атрибута gd:etag,

Чтобы получить изображение для каждого контакта, ПОЛУЧИТЕ этот URL:

https://www.google.com/m8/feeds/photos/media/{userEmail}/{contactId}

Полная документация по API контактов Google.

Другие вопросы по тегам