我正在从 Python 脚本运行 Google App 脚本可执行 API。我正在使用服务帐户执行此操作,以便可以安排无人值守运行。
我尝试使用我自己的帐户来执行此操作,并且 OAuth 通过打开浏览器页面并请求授权来工作。在我授权脚本执行后。我已按照以下链接中的建议将范围授权给服务帐户
https://developers.google.com/identity/protocols/OAuth2ServiceAccount
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
from google.oauth2 import service_account
import googleapiclient.discovery
import httplib2
import json
SCRIPT_ID ='xyz'
SCOPES = ['https://www.googleapis.com/auth/documents' ,'https://www.googleapis.com/auth/forms', 'https://www.googleapis.com/auth/presentations','https://www.googleapis.com/auth/spreadsheets']
service_account_info = json.load(open('service_account_key_file.json'))
creds = service_account.Credentials.from_service_account_info( service_account_info)
service = build('script', 'v1', credentials=creds)
request = {"function": "testExecutableSA","parameters": ["TEST RUN"]}
try:
response = service.scripts().run(body=request,
scriptId=SCRIPT_ID).execute()
currentdata = response
print(currentdata)
except errors.HttpError as e:
# The API encountered a problem before the script started executing.
print(e.content)response = service.scripts().run(body=request, scriptId=SCRIPT_ID).execute()
当我使用我的帐户执行此操作时,脚本运行并通过被称为“这是一个”测试运行“的 App 脚本记录测试消息
当我使用服务帐户文件执行此操作时,出现以下错误
b'{\n "error": {\n "code": 400,\n "message": "请求包含无效参数。",\n "errors": [\n {\n "message": "请求包含无效参数。",\n "domain": "global",\n "reason": "badRequest"\n }\n ],\n "status": "INVALID_ARGUMENT"\n }\n}\ n'
没有关于无效论点的详细信息。
只有这个改变的http_authorized
是传递的对象。
我是在犯错还是有什么东西坏了?