通过Google联系人API或人员API创建新联系人

问题描述 投票:0回答:1

是否可以使用Google联系人API或人员API创建Google联系人?

我在使用Google API创建新联系人时遇到问题。

我正在搜索几天,发现以下信息:

1-好像人的API包取代了Google联系人API

https://gsuite-developers.googleblog.com/2017/07/google-people-api-now-supports-updates.html

2-许多人无法使用gdata和atom包使用python 3+创建新联系人。

3-人员API按照Gsuite的建议出现

https://support.google.com/a/answer/6103110?hl=pt-BR

我想知道是否有人使用这些google API创建新的联系人。

是否需要g套件电子邮件?

我如何获得访问令牌?

我已经在Google Cloud Platform上完成了所有设置(启用API和auth2),我具有json文件,秘密密钥和客户端ID

编辑:

我正在使用此代码列出我的50个联系人,我必须修改块以创建新的联系人

from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/contacts']

def main():
    """Shows basic usage of the People API.
    Prints the name of the first 10 connections.
    """
    creds = None
    # The file token.pickle stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('people', 'v1', credentials=creds)

    # Call the People API
    print('List 50 connection names')
    results = service.people().connections().list(
        resourceName='people/me',
        pageSize=50,
        personFields='names,emailAddresses').execute()
    connections = results.get('connections', [])

    for person in connections:
        names = person.get('names', [])
        if names:
            name = names[0].get('displayName')
            print(name)

if __name__ == '__main__':
    main()
python api google-contacts-api gsuite google-people-api
1个回答
0
投票

由于您已经具有列出联系人的身份验证功能,因此您应该可以执行以下操作来创建联系人:

newContact = { "names": [{ "givenName": "John", "familyName": "Doe" }] }
result = service.people().createContact(body=newContact).execute()

人体/人体内的完整定义是here

© www.soinside.com 2019 - 2024. All rights reserved.