这是我的 Python 方面。
...
SCRIPT_ID = '<script id>'
creds = GetGoogleCredentials()
gscripts = build( 'script', 'v1', credentials = creds )
# Create an execution request object.
request = {
"function": "test1",
"devMode": True,
"parameters": [{
"1": "hi",
"3": "bye",
"a5": "yes"
}]
}
# Make the API request.
response = gscripts.scripts().run(
body = request,
scriptId = SCRIPT_ID
).execute()
print( response )
这是 Apps 脚本方面:
function test1( event ) {
Logger.log( event );
Logger.log( event[1] );
Logger.log( event["3"] );
Logger.log( event["a5"] );
}
记录器中的输出:
[20-01-16 16:34:21:530 PST] {1=hi, 3=bye, a5=yes}
[20-01-16 16:34:21:531 PST] undefined
[20-01-16 16:34:21:531 PST] undefined
[20-01-16 16:34:21:532 PST] yes
我一直在试图弄清楚我做错了什么以及为什么当我尝试索引它时对象返回未定义,即使记录器能够读取这些值也是如此。似乎与使用数字作为未正确处理的对象键有关。起初我确信我在做一些愚蠢的事情,但这是我缩小范围的测试用例。