【问题标题】:Google Drive api v3 (java): Deleting a resource property does not workGoogle Drive api v3 (java):删除资源属性不起作用
【发布时间】:2018-04-18 21:35:01
【问题描述】:

我正在使用适用于 Java 的 Google Drive API (v3-rev111-1.23)。我正在尝试从资源中删除属性。 我遵循了这个文档:

https://developers.google.com/drive/v3/reference/files/update https://developers.google.com/drive/v3/web/migration#methods

这是我写的代码:

Drive service = getDriveService();
File file = new File();
Map<String,String> properties = new HashMap<>();
properties.put("propA", null);
file.setProperties(properties);

file = service.files().update(fileId, file).execute();

问题是该属性永远不会被清除。保持之前的值。

如果我用以下方式编写生成的 json:

System.out.println(service.files().update(fileId, file).getJsonContent());

我明白了:

{properties={propA=null}}

使用相同的代码添加新属性,如:

properties.put("test", "yes");

我明白了:

{properties={test=yes}}

它可以正常工作。

有人遇到并解决了这个问题吗?

我从 2016 年开始阅读 Google Drive Java API V3 delete custom property 这个帖子,但没有给出解决方案。


更多细节:

使用网络上的试用版 (https://developers.google.com/drive/v3/reference/files/update) 我可以创建属性、修改它们甚至删除它们。

谢谢。

【问题讨论】:

    标签: java google-drive-api


    【解决方案1】:

    以下是我可以分享的内容,使用 Try-its 可能会对您有所帮助:

    我使用Files.create 创建了一个文件并创建了一个自定义属性

    appProperties{
      "supersaiyan": "yes"
    }
    

    然后我用Files.update删除了它:

    appProperties{
      "supersaiyan": null
    }
    

    当我尝试获取appProperties 时,我得到了{},这意味着已成功删除。

    【讨论】:

    • 我也使用了试用版,但无法复制问题。我能够向同一资源添加和删除属性。我可以通过从控制台列出来查看该属性是如何被删除的。
    猜你喜欢
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多