gpt4 book ai didi

c# - Apps 脚本 API 响应没有 "result" key

转载 作者:太空宇宙 更新时间:2023-11-03 14:47:23 25 4
gpt4 key购买 nike

我创建了一个 Google Apps 脚本项目来将文件上传到 Google Drive,并用 C# 构建了一个应用程序来执行这个脚本。我使用了 documentation's guide 中给出的示例代码

但是,当我通过 Apps Script API 调用我的函数时,我的 C# 应用程序引发了以下异常:

System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.'

当执行这一行时:

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");
}
}

如果我将“result”更改为“@type”,则会显示此错误

无法将“System.String”类型的对象转换为类型“Newtonsoft.Json.Linq.JObject”。

最佳答案

您的 Google App Script 函数很可能没有返回语句。 API 未找到任何结果。我遇到了同样的问题。

function someFunction () {
// some code here
return "something";
}

关于c# - Apps 脚本 API 响应没有 "result" key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53556365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com