谷歌人的API返回空/没有结果在Python

2022-01-25 07:53:20 标签 apigoogle-apigoogle-people-api

我试图从我的人gmail帐户和谷歌提供的指示从人们API返回一个空列表。我不知道为什么。我在几年前尝试过另一种解决方法,但似乎不起作用。我将我的代码粘贴在下面。任何帮助排除这是感谢!

import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/contacts.readonly']
from google.oauth2 import service_account
SERVICE_ACCOUNT_FILE = '<path name hidden>.json'
credentials = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE, scopes=SCOPES)
def main():
    #Shows basic usage of the People API.
    #Prints the name of the first 10 connections.
    
    creds = None
    
    service = build('people', 'v1', credentials=credentials)
    # Call the People API
    print('List 10 connection names')
    results = service.people().connections().list(
        resourceName='people/me',
        pageSize=10,
        personFields='names,emailAddresses').execute()
    connections = results.get('connections', [])
    request = service.people().searchContacts(pageSize=10, query="A", readMask="names")
    results = service.people().connections().list(resourceName='people/me',personFields='names,emailAddresses',fields='connections,totalItems,nextSyncToken').execute() 
    for i in results:
        print ('result', i)
    for person in connections:
        names = person.get('names', [])
        if names:
            name = names[0].get('displayName')
            print(name)
if __name__ == '__main__':
    main()
阅读全文

▼ 版权说明

相关文章也很精彩
推荐内容
更多标签
相关热门
全站排行
随便看看

错说 cuoshuo.com —— 程序员的报错记录

部分内容根据CC版权协议转载;网站内容仅供参考,生产环境使用务必查阅官方文档

辽ICP备19011660号-5

×

扫码关注公众号:职场神器
发送: 1
获取永久解锁本站全部文章的验证码