【问题标题】:Domain Shared Contacts API to create external contacts using python + service account (client library)域共享联系人 API 使用 python + 服务帐户(客户端库)创建外部联系人
【发布时间】: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

【问题讨论】:

    标签: google-api google-contacts-api google-people-api google-shared-contacts


    【解决方案1】:

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

    1. 我创建了一个服务帐户。

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

    3. 由于我使用的是 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)
    

    【讨论】:

    • 有人有兴趣拥有一条蟒蛇吗?这个库?
    猜你喜欢
    • 2022-01-22
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-10
    • 2018-02-22
    • 1970-01-01
    相关资源
    最近更新 更多