我几乎使用谷歌自己网站的样本
https://developers.google.com/apps-script/api/how-tos/execute
下面复制了示例 python 脚本的相关部分
from __future__ import print_function
from googleapiclient import errors
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file as oauth_file, client, tools
def main():
"""Runs the sample.
"""
SCRIPT_ID = 'ENTER_YOUR_SCRIPT_ID_HERE'
# Setup the Apps Script API
SCOPES = 'https://www.googleapis.com/auth/script.projects'
store = oauth_file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('script', 'v1', http=creds.authorize(Http()))
if __name__ == '__main__':
main()
我收到以下错误
File "test.py", line 67, in <module>
main()
File "test.py", line 22, in main
service = build('script', 'v1', http=creds.authorize(Http()))
File "C:\Users\pedxs\Anaconda2\lib\site-packages\googleapiclient\_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\pedxs\Anaconda2\lib\site-packages\googleapiclient\discovery.py", line 232, in build
raise e
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/discovery/v1/apis/script/v1/rest returned "Request contains an invalid argument.">
一周前我有这个确切的代码工作。第 22 行使用了发现构建功能,据我了解,该功能将凭据发送到 Google 的 API 身份验证器服务器“ https://www.googleapis.com/discovery/v1/apis/script/v1/rest ”。我怀疑这是谷歌方面的问题,因为即使他们的示例代码也不起作用。
我尝试创建一个新的 Google Cloud Platform 并获取一个新的 credentials.json 文件。我还尝试使用不同的电子邮件帐户进行身份验证。