【问题标题】:Google Contact API : how to get the google api contact image?Google Contact API:如何获取 google api 联系人图片?
【发布时间】:2014-09-29 05:48:57
【问题描述】:

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

)

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      使用以下语句,其中 $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 .'';
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-04
        相关资源
        最近更新 更多