【问题标题】:Updating file on GoogleDrive (App Folder)更新 Google Drive 上的文件(应用程序文件夹)
【发布时间】:2019-12-12 07:14:52
【问题描述】:

我正在将我的领域数据库的备份上传到 appfolder 内的 Google Drive,但问题是每当我上传备份时,它都会生成新的备份文件并增加驱动器的存储空间。 我试过用

更新它

mDriveService.files().update(existingToken,metadata, inputStreamContent);

但这给了我以下错误:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 
Forbidden

{
“code”: 403,
“errors”: [
{
  “domain”: “global”,
  “message”: “The parents field is not directly writable in update requests. Use the addParents and removeParents parameters instead.“,
  “reason”: “fieldNotWritable”
}
],
“message”: “The parents field is not directly writable in update requests. Use the addParents and removeParents parameters instead.”
}

当我尝试删除它时,它给了我以下错误:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden


{
“code”: 403,
“errors”: [
{
  “domain”: “global”,
  “message”: “The resource body includes fields which are not directly writable.“,
  “reason”: “fieldNotWritable”
}
 ],
 “message”: “The resource body includes fields which are not directly 
writable.”
}

我只想更新文件或用新文件替换现有文件。

【问题讨论】:

  • 能否请您提供您正在执行的请求的代码以检查它是否正确编写。您是否拥有尝试更新的父文件夹的权限?
  • @Kessy 我不知道如何授予 parent 权限。请告诉我。
  • 如果它是你的驱动器,你应该拥有所有的权限,所以这将是一个与代码相关的问题。如果是共享云端硬盘,您应该请求该云端硬盘的所有者授予您权限。
  • @Kessy 我找不到任何授予权限的方法,您能帮帮我吗?
  • 您是该文件夹的所有者吗?您也可以阅读这 2 个文档:通过代码授予权限:developers.google.com/drive/api/v3/reference/permissions 通过驱动器授予权限:support.google.com/drive/answer/…

标签: android google-drive-api realm drive


【解决方案1】:
mService.files().update(fileId, metadata, generateFileContents())
                .setFields("id, name, appProperties")
                .execute();

fileId 是您要更新的文件的 ID。

【讨论】:

    【解决方案2】:

    我也遇到了这个问题,用code解决了:

     uploadedFile = mDriveService.files().update(fileId, null, mediaContent).execute();
    

    fileId 是要更新的文件的 google 驱动器 ID。

    请注意将第二个参数传递为null,实际内容将在第三个参数中传递。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-13
      • 1970-01-01
      • 2011-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多