Google Contact API:如何获取Google API联系人图片?

时间:2014-09-29 05:48:57

标签: google-api google-contacts google-client

我从谷歌联系API获得以下回复:

   SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [rel] => http://schemas.google.com/contacts/2008/rel#edit-photo
            [type] => image/*
            [href] => https://www.google.com/m8/feeds/photos/media/username%40domain.com/3f800ef08589236/I_BQwBZUKwmNsRvSkFXR-A
        )

)
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [rel] => http://schemas.google.com/contacts/2008/rel#photo
            [type] => image/*
            [href] => https://www.google.com/m8/feeds/photos/media/username%40domain.com/3f800ef08589236
        )

)
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [rel] => self
            [type] => application/atom+xml
            [href] => https://www.google.com/m8/feeds/contacts/username%40domain.com/full/3f800ef08589236
        )

)
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [rel] => edit
            [type] => application/atom+xml
            [href] => https://www.google.com/m8/feeds/contacts/username%40domain.com/full/3f800ef08589236/1396967693060001
        )

)

但我无法使用此数据获取图片,任何人都可以告诉我如何使用此数据获取联系人图像?

2 个答案:

答案 0 :(得分:1)

它是你在那里列出的第二个对象中的href。向该网址发送经过身份验证的请求,您就可以获得该照片。

答案 1 :(得分:0)

使用以下内容,其中$ client是Google_Client()的对象;

foreach ($temp['feed']['entry'] as $image) {
  if (isset($image['link'][0]['href']))
  {
    $photo=new Google_HttpRequest($image['link'][0]['href']);
    $photo_val=$client->getIo()->authenticatedRequest($photo);
    $photo_return=$photo_val->getResponseBody();
    $imgData=base64_encode($photo_return);
    $pro_image='data:image/jpeg;base64,'.$imgData .'';
  }
}