gpt4 book ai didi

node.js - 使用 googledrive.files.copy 时设置新文件名

转载 作者:太空宇宙 更新时间:2023-11-03 23:51:56 24 4
gpt4 key购买 nike

我正在使用 Google Drive APIV3 将电子表格复制到 Google Drive 上的文件夹中。该文档指出应使用“name”属性来设置新工作表的标题。我正在使用它,但新创建的工作表被命名为“{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显示的是默认命名而不是“i'm a copy”。

任何方向将不胜感激。谢谢

https://developers.google.com/drive/api/v3/reference/files/copy

最佳答案

  • 您想要使用 Drive API v3 中的“文件:复制”方法来复制文件。
  • 您希望使用 googleapis 和 Node.js 来实现此目的。
  • 您已经能够使用 Drive API。

如果我的理解是正确的,这个答案怎么样?

修改后的脚本:

在此修改中,copyRequestdrive.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);
}
);

注意:

  • 如果出现错误,请使用最新版本的 googleapi。

引用:

如果我误解了您的问题并且这不是您想要的结果,我深表歉意。

关于node.js - 使用 googledrive.files.copy 时设置新文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59025843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com