我正在使用Google Drive apiv3将电子表格复制到Google Drive上的文件夹中。文档指出应使用“名称”属性设置新工作表的标题。我正在使用它,但是新创建的工作表名为“ {titleOfSheetToCopy}的副本”。
请求:
app.get('/new', function (req, res)
{
var drive = google.drive({version:'v3', auth: jwt_client});
var copyRequest = {
name: 'im a copy',
fileId: 'idOfSheetToClone',
parents: ['idOfDestinationFolder'],
}
drive.files.copy(copyRequest, function(err, response){
if(err){
console.log(err);
res.send('error');
return;
}
res.send(response);
});
});
响应:
{
"config": {
"url": "https://www.googleapis.com/drive/v3/files/-----/copy?name=im%20a%20copy&parents=---",
"method": "POST",
"headers": {
"Accept-Encoding": "gzip",
"User-Agent": "google-api-nodejs-client/0.7.2 (gzip)",
"Authorization": "---",
"Accept": "application/json"
},
"params": {
"name": "im a copy",
"parents": [
"---"
]
},
"responseType": "json"
},
"data": {
"kind": "drive#file",
"id": "---",
"name": "Copy of _template",
"mimeType": "application/vnd.google-apps.spreadsheet"
},
"headers": {
"alt-svc": "quic=\":443\"; ma=2592000; v=\"46,43\",h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000",
"cache-control": "no-cache, no-store, max-age=0, must-revalidate",
"connection": "close",
"content-encoding": "gzip",
"content-type": "application/json; charset=UTF-8",
"date": "Mon, 25 Nov 2019 05:37:01 GMT",
"expires": "Mon, 01 Jan 1990 00:00:00 GMT",
"pragma": "no-cache",
"server": "GSE",
"transfer-encoding": "chunked",
"vary": "Origin, X-Origin",
"x-content-type-options": "nosniff",
"x-frame-options": "SAMEORIGIN",
"x-xss-protection": "1; mode=block"
},
"status": 200,
"statusText": "OK"
}
可以看到response.data.name显示了默认命名,而不是“我是副本”。
任何方向将不胜感激。谢谢
https://developers.google.com/drive/api/v3/reference/files/copy
如果我的理解是正确的,那么这个答案呢?
在该变形例中,copyRequest
与drive.files.copy()
被修改如下。
var copyRequest = { // Modified
name: "im a copy",
parents: ["idOfDestinationFolder"]
};
drive.files.copy(
{ // Modified
fileId: "idOfSheetToClone",
requestBody: copyRequest // or resource: copyRequest
},
function(err, response) {
if (err) {
console.log(err);
res.send("error");
return;
}
res.send(response);
}
);
如果我误解了您的问题,而这不是您想要的结果,我深表歉意。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句