首页 > 解决方案 > 尝试在 GDrive API v3 上创建评论时出错

问题描述

尝试使用 GDrive API 在 Google 表格文件中创建评论并收到以下错误:

Google.Apis.Requests.RequestError 此方法需要“fields”参数。[400] 错误[消息[此方法需要 'fields' 参数。] Location[fields - parameter] Reason[required] Domain[global] ]

不确定在哪里指定 fields 参数?

我尝试搜索放置参数的位置,并查看了 v2 和 v3 文档,这两个文档都没有表明需要指定字段参数。

下面是我正在使用的代码:

string result = "success";
try {
    Comment oBody = new Comment {
        Content = commentText,
        Anchor = "{'r': 0, 'a': [{'matrix':{'c': 4}},  {'matrix':{'r': 4}}]}"
    };
    Comment oRequest = driveService.Comments.Create(oBody, fileId).Execute();
} catch (Exception e) {
    result = "Google API: " + e.Message;
}
textBox1.Text = result;
return result;

标签: c#google-drive-api

解决方案


韦尔普,我已经设法通过自己的代码并解决了它。我想出了在哪里指定 fields 参数,现在只是将响应吐出到一个字符串。我注释掉了锚,因为我还不知道它的结构(显示的锚是谷歌在我通过 ID 获取评论时显示的内容)。

Comment oBody = new Comment {
    Content = commentText,
    //Anchor = "{\"type\":\"workbook-range\",\"uid\":0,\"range\":\"1561003787\"}",
};
CommentsResource.CreateRequest oRequest = driveService.Comments.Create(oBody, fileId);
oRequest.Fields = ("*");
Comment oResponse = oRequest.Execute();
result = JsonConvert.SerializeObject(oResponse, Formatting.Indented);

推荐阅读