2014-10-17 745 views
1

我想通過谷歌API 3.0獲取所有用戶詳細信息的用戶聯繫人。 我能夠得到與用戶的細節JSON響應。如何使用PHP獲取用戶的'contactid'使用谷歌API

$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&alt=json&v=3.0&oauth_token='.$accesstoken; 

結果是

[entry] => Array 
      (
       [0] => Array 
        (
         [id] => Array 
          (
           [$t] => http://www.google.com/m8/feeds/contacts/sfdhitdf1%40gmail.com/base/1 
          ) 

         [gd$etag] => "RXc7fTVSLit7I2A9XRZaEkoLRAw." 
         [updated] => Array 
          (
           [$t] => 2014-08-29T00:16:24.905Z 
          ) 

         [app$edited] => Array 
          (
           [xmlns$app] => http://www.w3.org/2007/app 
           [$t] => 2014-08-29T00:16:24.905Z 
          ) 

         [category] => Array 
          (
           [0] => Array 
            (
             [scheme] => http://schemas.google.com/g/2005#kind 
             [term] => http://schemas.google.com/contact/2008#contact 
            ) 

          ) 

         [title] => Array 
          (
           [$t] => abc 
          ) 

         [link] => Array 
          (
           [0] => Array 
            (
             [rel] => http://schemas.google.com/contacts/2008/rel#photo 
             [type] => image 
             [href] => https://www.google.com/m8/feeds/photos/media/sachdfwdfd%40gmail.com/1?v=3.0 
             [gd$etag] => "VWVIH3oyWit7I2B0UBRURzwNBWM8ODs8cSk." 
            ) 

           [1] => Array 
            (
             [rel] => self 
             [type] => application/atom+xml 
             [href] => https://www.google.com/m8/feeds/contacts/sachitdff%40gmail.com/full/1?v=3.0 
            ) 

           [2] => Array 
            (
             [rel] => edit 
             [type] => application/atom+xml 
             [href] => https://www.google.com/m8/feeds/contacts/sachidtfd%40gmail.com/full/1?v=3.0 
            ) 

          ) 

         [gd$name] => Array 
          (
           [gd$fullName] => Array 
            (
             [$t] => abc xyz 
            ) 

           [gd$givenName] => Array 
            (
             [$t] => abc 
            ) 

           [gd$familyName] => Array 
            (
             [$t] => xyz 
            ) 

          ) 

         [gd$email] => Array 
          (
           [0] => Array 
            (
             [address] => [email protected] 
             [primary] => true 
             [rel] => http://schemas.google.com/g/2005#other 
            ) 

          ) 

         [gContact$website] => Array 
          (
           [0] => Array 
            (
             [href] => http://www.google.com/profiles/104048264070958665151 
             [rel] => profile 
            ) 

          ) 

         [gContact$groupMembershipInfo] => Array 
          (
           [0] => Array 
            (
             [deleted] => false 
             [href] => http://www.google.com/m8/feeds/groups/sachitaware 

          ) 

        ) 

但在這裏我不明白的接觸式圖像的user.The documentation說我需要一個接觸式ID用於獲取照片,但我不明白上述回覆中的聯繫人ID。如何獲取用戶的聯繫人ID以及他的聯繫人照片?

我已經授權使用oauth 2.0的應用程序,除了圖像以外,我獲得了大部分聯繫人的詳細信息。

編輯:我試圖this方式從文檔和它的作品,但它返回的二進制圖像,而不是圖像URL,我必須再次提出請求,以獲得圖像。

$url1 ='https://www.google.com/m8/feeds/photos/media/{useremail}/13444?  v=3.0&oauth_token='.$accesstoken; 
$xmlresponse1 = curl($url1); 

要顯示的圖像:

<img src="data:image/*;base64,<?php echo base64_encode($xmlresponse1); ?> /> 

我還是不能接觸式圖像URL類似Facebook的回報?

回答

2

根據該文件,contactIid在通過API返回的聯繫人條目URL返回:

http://www.google.com/m8/feeds/contacts/<userEmail>/base/<contactId> 

所以,給你的樣品:

http://www.google.com/m8/feeds/contacts/sfdhitdf1%40gmail.com/base/1 

我們有這些值:

userEmail: [email protected] 
contactId: 1 
+0

在userEmail中,我在輸出中的每一處都有我的電子郵件ID,並且基值始終在變化數字轉換爲字母。例如:'http:// www.google.com/m8/feeds/contacts/sachitaware21%40gmail.com/base/f'和'http://www.google.com/m8/feeds/觸點/ sachitaware21%40gmail.com /鹼/ 13'。我有這兩個作爲聯繫人的URL,所以f和13分別是聯繫人ID嗎? – KillABug 2014-10-18 06:40:01

+0

是不是將聯繫人圖像的URL與聯繫人列表API一起返回?否則,每次我想要獲取聯繫人圖像時,都必須發送針對每個聯繫人的單獨請求。如果列表很大,這將需要很長時間。 – KillABug 2014-10-18 07:44:42