Python 名称错误:名称';构建';没有定义

Python 名称错误:名称';构建';没有定义,python,python-3.x,google-calendar-api,Python,Python 3.x,Google Calendar Api,我正在尝试编写一个python脚本来从google日历中获取条目 我得到一个NameError:未为以下行定义名称“build”: service=build('calendar','v3',credentials=credentials) 有什么建议可以解决这个问题吗?试试这个: from apiclient import discovery ... credentials = flow.run_console() http = credentials.authorize(httplib2.H

我正在尝试编写一个python脚本来从google日历中获取条目

我得到一个
NameError:未为以下行定义名称“build”:

service=build('calendar','v3',credentials=credentials)

有什么建议可以解决这个问题吗?

试试这个:

from apiclient import discovery
...
credentials = flow.run_console()
http = credentials.authorize(httplib2.Http())
service = discovery.build('calendar', 'v3', http=http)
您可以使用作为参考

请注意,在导入部分中,生成方法是从哪个模块派生的:

from __future__ import print_function
from apiclient.discovery import build //notice the build here
from httplib2 import Http
from oauth2client import file, client, tools
import datetime
在这里使用之前:

service = build('calendar', 'v3', http=creds.authorize(Http()))

你认为口译员在哪里找到的?您的唯一导入语句是选择性的,因为您只将
InstalledAppFlow
导入全局命名空间。不确定,是否必须包含一条语句才能将生成导入全局命名空间?导入或定义的
build
在何处?脚本告诉您,您正在调用一个尚未定义的函数