2

在寻找列出OtherGmail/GSuite 用户的所有(包括)联系人的过程中。当前People API不支持此功能,请注意以下线程:

深入研究时,联系人 API 似乎仍在运行,可以通过gdata https://developers.google.com/contacts/v3/使用

但是,基于以下 repo ( https://github.com/google/gdata-python-clientuserID ),关于使用 OAuth2 ( , token, )实现的文档有限refreshToken,这是获取列表的当前绊脚石Other Contacts

任何帮助将不胜感激,谢谢!

4

1 回答 1

2

我在7 年前发现了这篇文章https://gist.github.com/jorilallo/3686737 (?)。下面的实际示例代码我必须对其进行一些修改才能使其正常工作:

import gdata
import gdata.gauth
import gdata.contacts.client
import json
import requests

GOOGLE_CLIENT_ID = 'GOOGLE_CLIENT_ID'  # Provided in the APIs console
GOOGLE_CLIENT_SECRET = 'GOOGLE_CLIENT_SECRET'  # Provided in the APIs console
ACCESS_TOKEN = 'ACCESS_TOKEN' # given from a prior OAuth2 workflow, along with userID and refreshToken
REFRESH_TOKEN = 'REFRESH_TOKEN'

# GData with access token
token = gdata.gauth.OAuth2Token(
    client_id=GOOGLE_CLIENT_ID,
    client_secret=GOOGLE_CLIENT_SECRET,
    scope='https://www.google.com/m8/feeds',
    user_agent='app.testing',
    access_token=ACCESS_TOKEN,
    refresh_token=REFRESH_TOKEN)

contact_client = gdata.contacts.client.ContactsClient()
token.authorize(contact_client)

feed = contact_client.GetContacts()

for entry in feed.entry:
  entry.title.text
  for e in entry.email:
    e.address

# JSON with access token
r = requests.get('https://www.google.com/m8/feeds/contacts/default/full?access_token=%s&alt=json&max-results=50&start-index=0' % (access_token))
data = json.loads(r.text)
print data
于 2019-01-31T21:47:22.593 回答