Google Drive API v2 – Single-parent model enforcement is there an issue if enforceSingleParent is not set to TRUE?

huangapple go评论61阅读模式
英文:

Google Drive API v2 - Single-parent model enforcement is there an issue if enforceSingleParent is not set to TRUE?

问题

关于 Google Drive 开发者通知有关不再支持文件具有多个父文件夹的内容(参考链接:https://developers.google.com/drive/api/v2/multi-parenting),提到在插入文件时将参数 'enforceSingleParent' 设置为 TRUE,以便“选择加入到旨在使所有项目仅具有一个父项的 API 行为”。

我已将我的 Drive API v2 升级到最新的 Java 版本 1.30.10,但是 Insert 类没有 'enforceSingleParent' 的设置方法。我已确保不再需要在我的 API 调用中使用多个文件父文件夹,并始终将父文件夹的值设置为单个父文件夹的 ID。然而,在 API 中关于此值的描述让我想知道是否还有其他要求,以确保在 9 月 30 日之前进行平稳的迁移。

除了确保不将文件设置为具有多个父文件夹之外,是否还有其他要求来支持这种单一父文件夹的迁移?

英文:

The Google Drive developer notification regarding the removal of support for files to have multiple parents (ref: https://developers.google.com/drive/api/v2/multi-parenting), there is mention of setting the parameter 'enforceSingleParent' to TRUE when inserting a file to "opt in to API behavior that aims for all items to have exactly one parent."

I've upgraded my Drive API v2 to the latest Java version of 1.30.10, however the Insert class does not have a setter for 'enforceSingleParent'. I have ensured that I no longer require multiple file parents for any of my API calls and always set the parents value to a single parent folder ID. However the description of this value in the API makes me wonder if there is any other requirement for its use to ensure a smooth migration come Sept 30.

Other than ensuring you don't set a file to have multiple parents, is there anything else required for to support this single parent migration?

答案1

得分: 0

如果您查看 Drive.java 的 Github 源代码,您将看到实际存在这样的 setter 方法。

Drive.java 的第 2715 行:

/**
 * Set to true to opt in to API behavior that aims for all items to have exactly one parent.
 * This parameter only takes effect if the item is not in a shared drive. If the child's owner
 * makes the request, the child is removed from all current folders and placed in the
 * requested folder. Any other requests that increase the number of the child's parents fail,
 * except when the canAddMyDriveParent file capability is true and a single parent is being
 * added.
 */
public Insert setEnforceSingleParent(java.lang.Boolean enforceSingleParent) {
    this.enforceSingleParent = enforceSingleParent;
    return this;
}

使用示例:

File file = service.files().insert(fileContent).setEnforceSingleParent(true).execute();

这可能是一个代码检查工具无法识别该方法的问题。在 IntelliJ IDEA 中,例如,它可以正常工作。

以下是如何正确更新项目中的依赖项的一些说明:

项目依赖项更新说明

参考

Drive v2 1.30.1 GitHub

Drive v2 Files insert

英文:

If you look at the Github source code for Drive.java you will see that such setter actually exists.

At line 2715 in Drive.java

      /**
       * Set to true to opt in to API behavior that aims for all items to have exactly one parent.
       * This parameter only takes effect if the item is not in a shared drive. If the child's owner
       * makes the request, the child is removed from all current folders and placed in the
       * requested folder. Any other requests that increase the number of the child's parents fail,
       * except when the canAddMyDriveParent file capability is true and a single parent is being
       * added.
       */
      public Insert setEnforceSingleParent(java.lang.Boolean enforceSingleParent) {
        this.enforceSingleParent = enforceSingleParent;
        return this;
      }

Use example:

File file = service.files().insert(fileContent).setEnforceSingleParent(true).execute();

It might be a linter issue not recognizing this method. In IntelliJ IDEA it works fine for example.

Here some instructions on how to correctly update the dependencies in your project:
https://github.com/googleapis/google-api-java-client-services/tree/master/clients/google-api-services-drive/v2/1.30.1#installation

Reference

Drive v2 1.30.1 GitHub

Drive v2 Files insert

huangapple
  • 本文由 发表于 2020年9月30日 02:16:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/64125362.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定