2014-09-29 230 views
0

我正在下面從谷歌聯繫人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 
     ) 

) 

但我不能用這個數據來獲取圖像,任何人都可以請讓我知道我怎樣才能使用這一數據接觸式圖像?

回答

1

這是你在那裏列出的第二個對象的href。發送一個認證請求到該URL,你會得到照片。

+0

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

0

使用以下代碼$ 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 .''; 
    } 
}