【问题标题】:Unable to change parents with Drive API v3无法使用 Drive API v3 更改父母
【发布时间】:2016-02-17 15:06:43
【问题描述】:

我正在从 Google Drive API V2 迁移到 V3。基本上我正在复制一个文件,重命名它,然后我试图将它移动到另一个文件夹。复制和重命名工作正常,但父更改什么也不做。您可以在下面找到代码 sn-p。

    Drive service = getDriveService("USERID");
    BatchRequest batch = service.batch();

    // I CREATE A COPY OF A FILE AND THEN I RENAME IT
    String documentID = ... // THE ID OF THE DOCUMENT I JUST CREATED
    // THEN I CHANGE PARENTS

    File newDocumentUpdateRemoveParents = new File();
    service.files().update(documentID, newDocumentUpdateRemoveParents).setRemoveParents("ORIGINALFOLDERID").queue(batch, new JsonBatchCallback<File>() {
        public void onSuccess(File content, HttpHeaders responseHeaders) {

        }
        public void onFailure(GoogleJsonError error, HttpHeaders responseHeaders) {

        }
    });

    File newDocumentUpdateAddParents = new File();
    service.files().update(documentID, newDocumentUpdateAddParents).setAddParents("NEWFOLDERID").queue(batch, new JsonBatchCallback<File>() {
        public void onSuccess(File content, HttpHeaders responseHeaders) {

        }
        public void onFailure(GoogleJsonError error, HttpHeaders responseHeaders) {

        }
    });

    batch.execute();

编辑:如果我在没有批处理的情况下直接使用执行...听起来像一个错误。

【问题讨论】:

  • 我没有任何问题。您是否检查过您有权将其移动到父文件夹?此外,添加一些 try/catch 块以查看应用程序中抛出的错误。希望这会有所帮助,祝你好运!
  • 从外观上看,问题似乎是您为update 方法提供了一个空的/新的File 对象。您应该提供实际的 File 或改用 patch() 方法,它允许这种语法。
  • 我使用空文件的原因是因为当前使用抛出异常的同一对象时存在错误。不过,它可能已在最新版本中修复。
  • 刚刚尝试使用同一个对象,仍然没有错误,仍然没有更改权限。
  • @Andres 完全没有错误,它总是继续 onSuccess,尝试调试。

标签: java google-api google-drive-api


【解决方案1】:

你可以试试这个:

service.files().update
(
   fileId='fileId',
   removeParents='source folder id',
   addParents='target folder id'
).execute();

【讨论】:

    猜你喜欢
    • 2021-07-15
    • 2017-11-04
    • 1970-01-01
    • 2019-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-29
    • 1970-01-01
    相关资源
    最近更新 更多