尝试在GDrive API v3上创建注释时出错

时间:2019-01-11 17:25:05

标签: c# google-drive-api

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

  

Google.Apis.Requests.RequestError       此方法需要'fields'参数。 [400]       错误[           Message [此方法需要'fields'参数。]           位置[字段-参数]原因[必填]域[全局]       ]

不确定在哪里指定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;

1 个答案:

答案 0 :(得分:0)

很高兴,我设法解决了自己的代码。我弄清楚了在哪里指定fields参数,现在只是将响应分散到一个字符串上。我注释掉了锚点,因为我还不知道它的结构(显示的锚点是当我执行“通过ID获取评论”时Google显示的内容)。

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);
相关问题