我创建了一个 Google Apps 脚本项目来将文件上传到 Google Drive,并用 C# 构建了一个应用程序来执行这个脚本。我使用了文档指南中给出的示例代码
但是,当我通过 Apps Script 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”类型。