如何使用 Google API 服务库 (Java) 运行 Google 应用程序脚本
How to run a Google App Script using Google API Service Library (Java)
按照Java Quickstart example, I am able to create a new Google App Script project and retrieve the scriptId. Also, by referring to the Restful API document,应该可以使用Method: scripts.run
执行脚本。但是,我不知道如何使用 Java 中的 com.google.api.services.script.Script
检索 return 值。
我试过:
Script scriptService = getScriptService();
Script.Scripts scripts = scriptService.scripts();
Script.Scripts.Run run = scripts.run(scriptId, request);
和反编译的run
函数:
public Script.Scripts.Run run(String var1, ExecutionRequest var2) throws IOException {
Script.Scripts.Run var3 = new Script.Scripts.Run(var1, var2);
Script.this.initialize(var3);
return var3;
}
该函数没有 return 我正在寻找的 ExecutionResponse
对象。
根据 REST API 文档,调用可能 包含 ExecutionResponse 的 script.run
does not immediately return an ExecutionResponse
object, but an Operation
对象:
{
"done": boolean,
// Union field result can be only one of the following:
"error": {
object(Status)
},
"response": object(ExecutionResponse)
,
// End of list of possible types for union field result.
}
如果我们查看 Java API Client library, we see that method Script.Script.run
接受脚本 ID 和 ExecutionRequest 的参数,然后 returns 一个必须是 .execute()
d 的 Script.Script.Run 请求:
Create a request for the method "scripts.run". This request holds the parameters needed by the script server. After setting any optional parameters, call the AbstractGoogleClientRequest.execute()
method to invoke the remote operation.
引用文档中引用的请求是Script.Script.Run
,并且有像.setAccessToken()
这样的方法用于额外的配置,还有像.execute()
和.executeMedia()
这样的几个执行方法来实际提交执行请求和 return 操作。
按照Java Quickstart example, I am able to create a new Google App Script project and retrieve the scriptId. Also, by referring to the Restful API document,应该可以使用Method: scripts.run
执行脚本。但是,我不知道如何使用 Java 中的 com.google.api.services.script.Script
检索 return 值。
我试过:
Script scriptService = getScriptService();
Script.Scripts scripts = scriptService.scripts();
Script.Scripts.Run run = scripts.run(scriptId, request);
和反编译的run
函数:
public Script.Scripts.Run run(String var1, ExecutionRequest var2) throws IOException {
Script.Scripts.Run var3 = new Script.Scripts.Run(var1, var2);
Script.this.initialize(var3);
return var3;
}
该函数没有 return 我正在寻找的 ExecutionResponse
对象。
根据 REST API 文档,调用可能 包含 ExecutionResponse 的 script.run
does not immediately return an ExecutionResponse
object, but an Operation
对象:
{
"done": boolean,
// Union field result can be only one of the following:
"error": {
object(Status)
},
"response": object(ExecutionResponse)
,
// End of list of possible types for union field result.
}
如果我们查看 Java API Client library, we see that method Script.Script.run
接受脚本 ID 和 ExecutionRequest 的参数,然后 returns 一个必须是 .execute()
d 的 Script.Script.Run 请求:
Create a request for the method "scripts.run". This request holds the parameters needed by the script server. After setting any optional parameters, call the
AbstractGoogleClientRequest.execute()
method to invoke the remote operation.
引用文档中引用的请求是Script.Script.Run
,并且有像.setAccessToken()
这样的方法用于额外的配置,还有像.execute()
和.executeMedia()
这样的几个执行方法来实际提交执行请求和 return 操作。