Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

python - 通过Google联系人API或人员API创建新的联系人(Create new contacts through google contacts API or people API)

Is it possible to create google contacts using the google contact APIs or people APIs?

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

I'm having trouble creating new contacts using the google APIs.

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

I'm searching for days and found the following information:

(我正在寻找几天,发现以下信息:)

1 - Looks like the people API package comes to replace google contacts API

(1-好像人的API包来取代Google联系人API)

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

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

2 - Many people are unable to create new contacts with python 3+ using gdata and atom packages.

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

3 - people API appears as recommended by Gsuite

(3-人们API出现,如Gsuite所建议)

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

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

I would like to know if anyone is creating new contacts using these google APIs.

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

Is ag suite email required?

(是否需要Ag Suite电子邮件?)

How do I get access token?

(如何获得访问令牌?)

I've done all the setup on google cloud platform (enable APIs and auth2), i have the json file, secret key and client id

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

edit:

(编辑:)

I am managing to list my 50 contacts with this code, I am having to modify the blocks to create new contacts

(我正在设法用此代码列出我的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()
  ask by Leonardo Henriques translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...