我联系了我正在使用的联系人同步脚本的作者,似乎还有另一种方法有效 - 这是当前修订版的链接,以及 Adler 先生最近提交的似乎解决了该问题的提交。请记住,这是 python,但我想可以使用 PHP 进行类似的检查?
https://github.com/michael-adler/sync-google-contacts
https://github.com/michael-adler/sync-google-contacts/commit/4c5a8517e9da84d59769d8b513f5b637782aea14
MAX_RESULTS 是之前设置的一个变量,10000,但也可能是 1500 或更少,因为这是我们得到的最大值。
query = gdc.ContactsQuery(max_results=MAX_RESULTS)
feed = self.gd_client.GetContacts(q=query)
while feed:
然后,检查更多联系人:
next_link = feed.GetNextLink()
if next_link:
feed = self.gd_client.GetContacts(uri=next_link.href)
else:
feed = None
如果您在 oauth2 Playground 中查看返回的 xml/json,您会看到响应包含一些有用的数据,您现在需要利用这些数据来完成这项工作。
例如,如果您发送(授权)请求
https://www.google.com/m8/feeds/contacts/default/full?max_results=10
响应包含
<openSearch:totalResults>1234</openSearch:totalResults>
这包含您的联系人数量。
还有一堆url链接返回。
我们需要的,如果存在,则表明有更多可用的联系人,由
标识
rel='下一个'
示例:
<link href='https://www.google.com/m8/feeds/contacts/username%40gmail.com/full?max-results=10' rel='self' type='application/atom+xml'/>
<link href='https://www.google.com/m8/feeds/contacts/username%40gmail.com/full?start-index=11&max-results=10' rel='next' type='application/atom+xml'/>
start-index 是总数的联系号码,因此如果您将 max_results 设置为 1000,并且您有 3500 个联系人,您将需要发送您的初始请求,然后从响应中提取每个“下一个”url需要后续(在本例中为 3 个)请求,附加后续数据,以将所有联系人添加到您的数组中。
您的初始查询可能是
https://www.google.com/m8/feeds/contacts/username%40gmail.com/full?&max_results=1000
您的后续请求将以
结尾
https://www.google.com/m8/feeds/contacts/username%40gmail.com/full?start-index=1001&max_results=1000
https://www.google.com/m8/feeds/contacts/username%40gmail.com/full?start-index=2001&max_results=1000
https://www.google.com/m8/feeds/contacts/username%40gmail.com/full?start-index=3001&max_results=1000 (would not return XML containing a link with rel='next' as this is the last page)