首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

通过google contacts API或people API创建新联系人

通过Google Contacts API或People API创建新联系人,可以使用以下步骤:

  1. 首先,你需要在Google Cloud控制台创建一个项目,并启用Contacts API或People API。你可以参考Google Cloud文档中的指南来完成这些步骤。
  2. 在你的项目中,你需要获取API密钥或OAuth 2.0凭据,以便进行身份验证和访问API。你可以在Google Cloud控制台的凭据页面中创建API密钥或OAuth 2.0凭据。
  3. 一旦你获得了API密钥或OAuth 2.0凭据,你可以使用它们来进行API调用。下面是一个示例代码片段,展示了如何使用Google Contacts API或People API创建新联系人:
代码语言:txt
复制
import google.auth
from google.auth.transport.requests import Request
from google.oauth2 import service_account
from googleapiclient.discovery import build

# 使用API密钥进行身份验证
api_key = 'YOUR_API_KEY'
service = build('people', 'v1', developerKey=api_key)

# 或者使用OAuth 2.0凭据进行身份验证
credentials = service_account.Credentials.from_service_account_file(
    'path/to/your/service_account.json',
    scopes=['https://www.googleapis.com/auth/contacts']
)
service = build('people', 'v1', credentials=credentials)

# 创建新联系人
new_contact = {
    'names': [
        {
            'givenName': 'John',
            'familyName': 'Doe'
        }
    ],
    'emailAddresses': [
        {
            'value': 'johndoe@example.com'
        }
    ]
}
created_contact = service.people().createContact(body=new_contact).execute()

# 打印新联系人的ID
print('Created contact ID: {}'.format(created_contact['resourceName']))

在上面的示例代码中,你需要将YOUR_API_KEY替换为你的API密钥,或者将'path/to/your/service_account.json'替换为你的OAuth 2.0凭据的JSON文件路径。

这样,你就可以使用Google Contacts API或People API成功创建新联系人了。

推荐的腾讯云相关产品:腾讯云API网关。腾讯云API网关是一种全托管的API管理服务,可以帮助开发者更轻松地创建、发布、维护、安全地扩展和监控API。它提供了丰富的功能,包括身份验证、访问控制、流量控制、缓存、日志记录等,可以帮助开发者更好地管理和保护API。你可以在腾讯云API网关的官方文档中了解更多信息和使用指南。

腾讯云API网关官方文档链接:https://cloud.tencent.com/document/product/628

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的合辑

领券