繁体   English   中英

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

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

我需要将GDrive文件夹创建到另一个GDrive文件夹中。

有代码:

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();
}

我得到这个错误...

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"
}

请帮我...

这个改装怎么样? 我认为从错误消息来看,问题的原因是由于fields的值。

从:

.setFields("id, parent")

至:

.setFields("id, parents")

笔记:

  • 请将parent修改为parents 在 Google Drive,在当前阶段,一个文件和文件夹有多个父级。 所以用了parents 但是我们可以看到下面的公告。 参考

    从 2020 年 9 月 30 日开始,将无法再将一个项目放置在多个文件夹中; 每个项目将只有一个位置。 在新的 model 中,可以使用快捷方式来组织多个层次结构中的内容。 Drive 文件夹结构和共享模型的这种简化将导致某些 Google Drive API 端点的行为方式发生变化。

    • 我不确定parents是否会更改为parent 因此,关于此,我想确认 2020 年 9 月 30 日之后驱动器 API 的更改。

参考:

暂无
暂无

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

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