域共享联系人 API 使用 python + 服务帐户(客户端库)创建外部联系人

Posted

技术标签:

【中文标题】域共享联系人 API 使用 python + 服务帐户(客户端库)创建外部联系人【英文标题】:Domain Shared Contacts API to create external contacts using python + service account (client library) 【发布时间】:2021-12-08 22:30:44 【问题描述】:

我想使用Domain Shared Contacts API 作为 python 客户端库的一部分。

我在其他情况下使用的流程: 创建凭据:

credentials = service_account.Credentials.from_service_account_info(....)

'创建'我稍后执行的服务对象

service = googleapiclient.discovery.build(service_name, api_version,credentials=credentials)

对于域共享联系人 API,我不知道要使用哪个 service_name 或 api_version Google API Discovery Service(如果有)。 是否可以使用联系人或人员 API 创建/更新/删除域的外部联系人?

如果没有,使用此 API 的过程是在您的代码库 Using OAuth 2.0 for Web Server Applications 中创建对 REST 端点的请求,例如: https://www.google.com/m8/feeds/contacts/example.com/full

【问题讨论】:

【参考方案1】:

我设法通过使用Domain Shared Contacts API 解决了我的问题

    我创建了一个服务帐户。

    使用示例 here 准备了授权 (HTTP/REST) API 调用。特别注意附加声明 sub

    由于我使用的是 Python,我安装了 pyjwt 并用它来创建和签署我的 JWT。作为秘密,我使用了 service_account.private_key:

    jwt.encode(jwt_claim_set, secret, algorithm="RS256")
    

然后根据用例(获取联系人,创建一个..)。我为我的请求分配了 Google 令牌(签名的 JWT)。

例子:

endpoint = 'https://www.google.com/m8/feeds/contacts//'.format(your_own_domain, projection_value)
headers = "Authorization": "Bearer " + token
gsuite_get_response = requests.get(endpoint, headers=headers)

【讨论】:

有人有兴趣拥有一条蟒蛇吗?这个库?

以上是关于域共享联系人 API 使用 python + 服务帐户(客户端库)创建外部联系人的主要内容,如果未能解决你的问题,请参考以下文章

在 Python 中使用域用户帐户访问 Windows 文件共享

JAVA通过http访问其他服务端API。

需要使用 jQuery Ajax 使用 Web API - 跨域资源共享 (CORS) 问题

手动获取文本到墙贴文本区域(使用 FB API 在 facebook 上共享 - Android)

如何使用微服务架构处理共享数据源

如何从Angular向同一域上的Laravel API发送请求?