Google 云端硬盘 API 父项插入错误“需要资源元数据”

Google Drive API parent insert error "Resource metadata required"

本文关键字:资源 元数据 错误 插入 硬盘 云端 API Google      更新时间:2023-09-26

我想在 Google 云端硬盘中为我的文件插入一个新的父级。这允许文件同时位于两个不同的文件夹中,具有相同的 FileID。这是我的代码:(我在 Node 上运行它.js并使用请求 Node 包,但这无论如何都不会有任何区别)。

var request_url = 'https://www.googleapis.com/drive/v2/files/' + FILE_ID + '/parents/';
 request.post({
   "url": request_url,
   'headers': {
     'Authorization': 'Bearer ' + accessToken
   },
   'body': JSON.stringify({
     id: PARENT_FOLDER_ID
   })
 }, function(response, body) {
   console.log(body);
 });

但是,我收到以下错误:

{
  "error": {
    "errors": [{
      "domain": "global",
      "reason": "resourceRequired",
      "message": "Resource metadata required"
    }],
    "code": 400,
    "message": "Resource metadata required"
  }
}

我搜索了Google云端硬盘的API文档,但没有找到任何相关的解决方案。

谷歌云端硬盘家长插入 API 参考:https://developers.google.com/drive/v2/reference/parents/insert

Google 云端硬盘 API 父级资源架构:https://developers.google.com/drive/v2/reference/parents#resource

任何帮助将不胜感激:)

而不是

 'body': JSON.stringify({
     id: PARENT_FOLDER_ID
   })

尝试

'json': {
         id: PARENT_FOLDER_ID
       }