Google 驱动器 API 父插入错误 "Resource metadata required"
Google Drive API parent insert error "Resource metadata required"
我想在 Google 驱动器中为我的文件插入一个新的父文件。这允许文件同时位于具有相同 FileID 的两个不同文件夹中。这是我的代码:(我在 Node.js 上 运行 并使用 request 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 Drive 的 API 文档,但没有找到任何相关的解决方案。
Google Drive Parents insert API 参考:
https://developers.google.com/drive/v2/reference/parents/insert
Google Drive API parents 资源模式:
https://developers.google.com/drive/v2/reference/parents#resource
任何帮助将不胜感激:)
而不是
'body': JSON.stringify({
id: PARENT_FOLDER_ID
})
尝试
'json': {
id: PARENT_FOLDER_ID
}
我想在 Google 驱动器中为我的文件插入一个新的父文件。这允许文件同时位于具有相同 FileID 的两个不同文件夹中。这是我的代码:(我在 Node.js 上 运行 并使用 request 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 Drive 的 API 文档,但没有找到任何相关的解决方案。
Google Drive Parents insert API 参考: https://developers.google.com/drive/v2/reference/parents/insert
Google Drive API parents 资源模式: https://developers.google.com/drive/v2/reference/parents#resource
任何帮助将不胜感激:)
而不是
'body': JSON.stringify({
id: PARENT_FOLDER_ID
})
尝试
'json': {
id: PARENT_FOLDER_ID
}