为了账号安全,请及时绑定邮箱和手机立即绑定

如何从 Python 脚本向 Google App Script API 传递参数?

如何从 Python 脚本向 Google App Script API 传递参数?

皈依舞 2021-11-16 10:41:34
我有一个SalesID要传递给 Google App Script的论点。我怎样才能通过这个 python 脚本传递它?(脚本来自https://developers.google.com/apps-script/api/how-tos/execute)from __future__ import print_functionfrom googleapiclient import errorsfrom googleapiclient.discovery import buildfrom httplib2 import Httpfrom oauth2client import file as oauth_file, client, toolsdef main(SalesID):    """Runs the sample.    """    SCRIPT_ID = '1WChnVrk5gycQEtumI7mPi5PexXafuhBAWN7-VnBK2aPkFpzMHtUp0cnx' #Actual Google Sheet Sample    # Setup the Apps Script API    SCOPES = ['https://www.googleapis.com/auth/script.projects','https://www.googleapis.com/auth/spreadsheets']    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()))    # Create an execution request object.    request = {"function": "getFoldersUnderRoot"}    try:        # Make the API request.        response = service.scripts().run(body=request,                scriptId=SCRIPT_ID).execute()        if 'error' in response:            # The API executed, but the script returned an error.            # Extract the first (and only) set of error details. The values of            # this object are the script's 'errorMessage' and 'errorType', and            # an list of stack trace elements.            error = response['error']['details'][0]            print("Script error message: {0}".format(error['errorMessage']))示例 Google 表格:https : //docs.google.com/spreadsheets/d/1Z4PAY3CCaRorn5LRdFQKn4-EcAHxwxHJsABzEgsSQk0/edit#gid=0基本上我希望能够将 SalesID 从 shell 传递到 Google 应用程序脚本进行处理。谢谢!
查看完整描述

1 回答

?
千万里不及你

TA贡献1784条经验 获得超9个赞

正如官方文档中所写,您必须在请求正文中提供它:

request = {"function": "myFunction", "parameters": [{"salesID" : 123}]}

也用 setValue(e.salesID);

查看完整回答
反对 回复 2021-11-16
  • 1 回答
  • 0 关注
  • 178 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信