0

我从 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
        )

)

但是我无法使用此数据获取图像,谁能告诉我如何使用此数据获取联系人图像?

4

2 回答 2

1

这是您在此处列出的第二个对象中的 href。向该 URL发送经过身份验证的请求,您将获得照片。

于 2014-09-30T22:59:09.573 回答
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 .'';
  }
}
于 2015-02-26T12:04:00.647 回答