备份gsuite用户联系人(带有服务帐户)

时间:2019-05-14 15:22:16

标签: python google-api gsuite googlecontactsapi google-people-api

我是Gsuite的管理员。

我有一项任务是收集我们g套件服务的所有用户的所有联系人的备份。

如何通过gmail api收集邮件-我知道。一切正常。

但与我接触时我已经走到了尽头:

  1. 创建了一个服务帐户

  2. 服务帐户的
  3. 个域设置具有https://www.googleapis.com/auth/contacts的权限。和其他范围

3.1。连接到Contacts-API时,我得到“ 该请求是有效的API密钥。”-为什么? (相同的服务帐户将获取所有电子邮件和日历事件...)
3.2。连接到People-api时:

  • 如果我使用凭据,我只能对自己的帐户(popeple / me)进行存款。with_subject(“ myemail @ mydomain”))

  • 如果简单服务帐户凭据-返回“仅支持“人/我”资源。”

问:

  1. People-API可能仅获得“人/我”联系吗?
  2. 我可用于域中所有用户的备份联系人的API是什么?

谢谢,对不起英语

范围

  • auth / gmail.readonly
  • 身份验证/联系人,
  • a / feeds / compliance / audit /,
  • m8 /提要

很好的代码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)

0 个答案:

没有答案