2017-01-20 40 views
0

搜索thru serverfault.com,stackoverflow.com,apple.stackexchange.com,谷歌搜索,仍然沒有得到太多。需要有人來幫忙。使用PHP從iCloud獲取電子名片

我試圖從iCloud帳戶獲取所有vCard。

我從Roundcube/CardDav的插件開始。

從物品,如:

stackoverflow.com/questions/24202551/manipulate-groups-in-icloud-with-carddav-protocol sabre.io/dav/building-a-carddav-客戶端/ sabre.io/dav/clients/osx-addressbook/ stackoverflow.com/questions/15111887/how-to-import-icloud-contacts-in-php# tools.ietf.org/html/rfc6352#section -8.7.1

我設法得到校長,校長的地址。但得到的0

這裏卡回送的ContentLength的最後一步是我做的:

- use icloud email as username 
- use icloud password 

要獲得校長,使用「HTTPS://contacts.icloud.com/」作爲URL ,PROPFIND,深度0:

<?xml version="1.0" encoding="UTF-8"?> 
    <d:propfind xmlns:d="DAV:"> 
     <d:prop> 
     <d:current-user-principal/> 
     </d:prop> 
    </d:propfind> 

響應:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
    <multistatus xmlns="DAV:"> 
     <response>  
      <href>/</href>      
      <propstat>    
       <prop>                   
        <current-user-principal> 
         <href>/1331115018/principal/</href> 
        </current-user-principal>                
       </prop>    
       <status>HTTP/1.1 200 OK</status>   
      </propstat>  
     </response> 
    </multistatus> 

接下來,這裏是我做的就是回家,USI NG 「的https:/ /contacts.icloud.com/1331115018/principal/」,PROPFIND,深度0:

<?xml version="1.0" encoding="UTF-8"?> 
    <d:propfind xmlns:d="DAV:" xmlns:card="urn:ietf:params:xml:ns:carddav"> 
     <d:prop> 
      <card:addressbook-home-set/> 
     </d:prop> 
    </d:propfind> 

響應:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
    <multistatus xmlns="DAV:"> 
     <response>  
      <href>/1331115018/principal/</href>      
      <propstat>    
       <prop>                   
        <addressbook-home-set xmlns="urn:ietf:params:xml:ns:carddav"> 
         <href xmlns="DAV:">https://p44-contacts.icloud.com:443/1331115018/carddavhome/</href> 
        </addressbook-home-set>                
       </prop>    
      <status>HTTP/1.1 200 OK</status>   
      </propstat>  
     </response> 
    </multistatus> 

最後,這是我做的,試圖讓所有的電子名片,使用的是https://p44-contacts.icloud.com:443/1331115018/carddavhome/,REPORT,深度爲1:

<?xml version="1.0" encoding="utf-8" ?>  
<C:addressbook-multiget xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav">  
    <D:prop>   
    <D:getetag/>   
     <C:address-data>   
     <C:prop name="UID"/>   
     <C:prop name="EMAIL"/>   
     <C:prop name="FN"/>   
     </C:address-data>  
    </D:prop>  
</C:addressbook-multiget> 

響應:

<?xml version="1.0" encoding="UTF-8"?> 
    <multistatus xmlns="DAV:" xmlns:CD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/"> 
    </multistatus> 

<?xml version="1.0" encoding="utf-8" ?> 
<C:addressbook-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav">  
    <D:prop>   
    <D:getetag/>   
     <C:address-data>   
     <C:prop name="UID"/>   
     <C:prop name="EMAIL"/>   
     <C:prop name="FN"/>   
     </C:address-data>  
    </D:prop>  
</C:addressbook-query> 

響應:

<?xml version="1.0" encoding="UTF-8"?> 
<multistatus xmlns="DAV:" xmlns:CD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/"> 
    <response>  
     <href>/1331115018/carddavhome/</href>     
     <propstat>     
      <prop>                      <getetag>"[email protected]=9123588c-8038-439c-a547-19c866d1ed06"</getetag>                             
      <address-data xmlns="urn:ietf:params:xml:ns:carddav"> 
      </address-data>                   
      </prop>      
     <status>HTTP/1.1 200 OK</status>     
     </propstat>    
    </response> 
</multistatus> 

<?xml version="1.0" encoding="utf-8" ?> 
<C:addressbook-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav">  
    <D:prop>   
    <D:getetag/>   
     <C:address-data>   
     <C:prop name="UID"/>   
     <C:prop name="EMAIL"/>   
     <C:prop name="FN"/>   
     </C:address-data>  
    </D:prop>  
    <C:prop-filter name="EMAIL">   
     <C:text-match collation="i;unicode-casemap" match-type="equals">me</C:text-match>   
     </C:prop-filter>  
    </C:filter>  
</C:addressbook-query> 

響應:

"Didn't understand the report" 

什麼d o我必須做什麼?

回答

0

CardDAV home(您的https://p44-contacts.icloud.com:443/1331115018/carddavhome/)包含CardDAV集合(又名'地址簿'),而不是vCards(包含聯繫人和聯繫人組)。你需要再跳一次。

您可以使用常規PROPFIND深度1列出家中的地址簿集合,然後使用您指定的報告來查詢這些聯繫人。像這樣:

PROPFIND /1331115018/carddavhome/ HTTP/1.1 
Depth: 1 
Host: p44-contacts.icloud.com:443 
Authorization: ... 
Content-Type: text/xml; charset=utf-8 
Content-Length: ... 

<propfind xmlns="DAV:"> 
    <prop> 
    <displayname /> 
    <resourcetype /> 
    </prop> 
</propfind> 

這將返回CardDAV家庭集合中所有子集合的列表。

其中有一個addressbookresourcetype是的CardDAV通訊錄集合,並可以使用addressbook-queryaddressbook-multiget報告如果支持進行查詢,使用sync-report(iCloud的那樣),或者用一個簡單的PROPFIND的集合。取決於你想要的。

給定一個地址簿收集URL,如果服務器支持,那麼'真實'客戶端通常會使用同步報告來獲取所有更改對象的URL,或者只抓取所有包含的URL,Content-Type和ETags使用PROPFIND作爲後備的vCards。例如:

PROPFIND /1331115018/carddavhome/contacts/ HTTP/1.1 
Depth: 1 
Host: p44-contacts.icloud.com:443 
Authorization: ... 
Content-Type: text/xml; charset=utf-8 
Content-Length: ... 

<propfind xmlns="DAV:"> 
    <prop> 
    <getetag /> 
    <getcontenttype /> 
    </prop> 
</propfind> 

這會爲您提供地址簿集合中所有對象的URL。然後您可以使用簡單的GET或一個multiget REPORT進行檢索。

順便說一句:在你的addressbook-multigetREPORT你沒有列出任何vCard的URL,因此結果集將永遠是空的......你可以在RFC 6352閱讀關於multiget。

注意:在iCloud中,家中通常只有一個地址簿集合,但在其他服務器中,通常有多個。同樣在一些服務器中,CalDAV和CardDAV家庭是相同的集合(即,記得實際檢查相應家庭集合中的子集合的資源類型)。

這是CardDAV的一個很好的介紹:Building a CardDAV client。 或這個在YouTube上:FOSDEM 2009 CalDAV

+0

Thx答覆。但我仍然不知道應該使用哪種XML。你能分享更多嗎? – charleslcso

相關問題