简体   繁体   English

将 Google Drive 文件夹创建到另一个文件夹时出错

[英]Error while creating Google Drive folder into another folder

I need create GDrive folder into another GDrive folder.我需要将GDrive文件夹创建到另一个GDrive文件夹中。

There's the code:有代码:

private static String createDriveFolder(String folderName, String mainFolder, Drive service) throws IOException {
    File fileMetadata = new File();
    fileMetadata.setName(folderName);
    fileMetadata.setParents(Collections.singletonList(mainFolder));
    fileMetadata.setMimeType("application/vnd.google-apps.folder");

    File file = service.files().create(fileMetadata)
            .setFields("id, parent")
            .execute();
    System.out.println("Folder ID: " + file.getId());
    return file.getId();
}

I get this error...我得到这个错误...

Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "location" : "fields",
    "locationType" : "parameter",
    "message" : "Invalid field selection parent",
    "reason" : "invalidParameter"
  } ],
  "message" : "Invalid field selection parent"
}

Please help me...请帮我...

How about this modification?这个改装怎么样? I think that from the error message, the reason of the issue is due to the value of fields .我认为从错误消息来看,问题的原因是由于fields的值。

From:从:

.setFields("id, parent")

To:至:

.setFields("id, parents")

Note:笔记:

  • Please modify parent to parents .请将parent修改为parents At Google Drive, in the current stage, a file and folder have the multiple parents.在 Google Drive,在当前阶段,一个文件和文件夹有多个父级。 So parents is used.所以用了parents But we can see the following announce.但是我们可以看到下面的公告。 Ref 参考

    Beginning Sept. 30, 2020, it will no longer be possible to place an item in multiple folders;从 2020 年 9 月 30 日开始,将无法再将一个项目放置在多个文件夹中; every item will have exactly one location.每个项目将只有一个位置。 In the new model, shortcuts can be used to organize content in multiple hierarchies.在新的 model 中,可以使用快捷方式来组织多个层次结构中的内容。 This simplification of Drive's folder structure and sharing models will result in a change in the way some Google Drive API endpoints behave. Drive 文件夹结构和共享模型的这种简化将导致某些 Google Drive API 端点的行为方式发生变化。

    • I'm not sure whether parents will be changed to parent .我不确定parents是否会更改为parent So about this, I would like to confirm the change of the Drive API after Sept. 30, 2020.因此,关于此,我想确认 2020 年 9 月 30 日之后驱动器 API 的更改。

Reference:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM