我正在从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“错误”:{\ n“代码”:400,\ n“消息”:“请求包含无效的参数。”,\ n“错误”:[\ n {\ n“消息“:”请求包含无效的参数。“,\ n”域“:”全局“,\ n”原因“:” badRequest“ \ n} \ n],\ n”状态“:” INVALID_ARGUMENT“ \ n} \ n} \ n'
没有关于无效参数的详细信息。
只有更改的是传递的http_authorized
对象。
我犯了一个错误或什么东西坏了吗?