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

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

问题描述:

我正在下面从谷歌联系人API响应:Google联系人API:如何获取google 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 
     ) 

) 

但我不能用这个数据来获取图像,任何人都可以请让我知道我怎样才能使用这一数据接触式图像?

这是你在那里列出的第二个对象的href。发送一个认证请求到该URL,你会得到照片。

+0

谢谢你,你救了我的一天 – mgsipl 2014-10-01 09:55:34

使用以下代码$ client是Google_Client()的Object;

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 .''; 
    } 
}