我是Gsuite的管理员。
如何通过gmail api收集邮件-我知道。一切正常。
但与我接触时我已经走到了尽头:
创建了一个服务帐户
个域设置具有https://www.googleapis.com/auth/contacts的权限。和其他范围
3.1。连接到Contacts-API时,我得到“ 该请求是有效的API密钥。”-为什么? (相同的服务帐户将获取所有电子邮件和日历事件...)
3.2。连接到People-api时:
如果我使用凭据,我只能对自己的帐户(popeple / me)进行存款。with_subject(“ myemail @ mydomain”))
如果简单服务帐户凭据-返回“仅支持“人/我”资源。”
问:
谢谢,对不起英语
范围
等
很好的代码people-api的示例,它与“ me”一起使用,但与其他用户不兼容:
class BlaBla():
....
def build_api(self, email, api, api_version, delegate = True):
self.email = email
credentials = service_account.Credentials.from_service_account_file(self.SERVICE_ACCOUNT_FILE, scopes = self.SCOPES)
if delegate:
delegated_credentials = credentials.with_subject(self.email)
self.service = build(api, api_version, credentials=delegated_credentials)
else:
self.service = build(api, api_version, credentials=credentials)
def get_user_contacts(self, email):
self.build_api(email=email, api="people", api_version="v1", delegate = True)
resourceName = "people/me"
connections = self.service.people().connections().list(resourceName=resourceName, pageSize = 10, personFields='names,emailAddresses').execute()
# connections - with my contacts
self.build_api(email=email, api="people", api_version="v1", delegate = False)
resourceName = "people/googleId..."
connections = self.service.people().connections().list(resourceName=resourceName, pageSize = 10, personFields='names,emailAddresses').execute()
# return "Only "people/me" resource is supported."
bla=BlaBla()
bla.get_user_contacts(args.email)