我创建了一个Google脚本项目来将文件上传到Google,并在C#中构建了一个应用程序来执行这个脚本。我使用了文献指南中给出的示例代码
但是,当我通过Apps脚本API调用我的函数时,我的C#应用程序会引发以下异常:
System.Collections.Generic.KeyNotFoundException
:“给定的密钥在字典中不存在。”
执行此行时:
Newtonsoft.Json.Linq.JObject folderSet = (Newtonsoft.Json.Linq.JObject)op.Response["result"];
这是相关的设置代码:
ExecutionRequest request = new ExecutionRequest();
request.Function = "uploadDocument";
IList<Object> prms = new List<Object>();
prms.Add(name.ToString());
prms.Add(dest);
prms.Add(file);
request.Parameters = prms;
ScriptsResource.RunRequest runReq =
service.Scripts.Run(request, scriptId);
try
{
// Make the API request.
Operation op = runReq.Execute();
if (op.Error != null)
{
IDictionary<string, object> error = op.Error.Details[0];
Console.WriteLine("Script error message: {0}", error["errorMessage"]);
}
else
{
Newtonsoft.Json.Linq.JObject folderSet =
(Newtonsoft.Json.Linq.JObject)op.Response["result"];
Console.WriteLine("ok");
}
}
如果我将“结果”更改为"@type“,则会显示此错误。
无法将“System.String”类型的对象强制转换为“Newtonsoft.Json.Linq.JObject”。
发布于 2019-06-06 23:21:01
最有可能的是,您的函数没有返回语句。API没有找到任何结果。我也有同样的问题。
function someFunction () {
// some code here
return "something";
}
https://stackoverflow.com/questions/53556365
复制相似问题