使用google drive.files.copy时设置新文件名

贾斯汀

我正在使用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

Tanaike
  • 您要使用文件方法:在Drive API v3中复制文件。
  • 您想使用带有Node.js的googleapis实现此目的。
  • 您已经可以使用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);
  }
);

注意:

  • 如果发生错误,请使用最新版本的googleapis。

参考:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用GAS克服Google Drive API Drive.Files.insert()方法的最大文件大小限制

来自分类Dev

匿名 Google Drive 上传创建新文件夹

来自分类Dev

在Google Drive API的v3版本中通过drive.files.copy转换通过nodejs使用API将Word文档转换为Google文档

来自分类Dev

使用Google Drive API SDK从Google Drive删除文件

来自分类Dev

使用Google Drive API在指定的Google Drive中上传文件

来自分类Dev

使用Google Advanced Drive服务使用Apps Script在文件夹中创建新文件

来自分类Dev

检查文件名是否存在并在Google脚本中更新文件名

来自分类Dev

如何根据部分文件名使用 Google Script 自动移动 Google Drive 中的文件?

来自分类Dev

使用Files.copy()选择文件名

来自分类Dev

Iterate Through Folders/Subfolders/Files in Google Drive

来自分类Dev

List of un syncable files in Google Drive

来自分类Dev

List of un syncable files in Google Drive

来自分类Dev

使用带有原始文件名和扩展名的Google Drive API下载

来自分类Dev

Google Drive Java Api-文件夹中的更新文件。

来自分类Dev

从新文件自动创建新的 Google Drive 文件夹

来自分类Dev

使用wget从Google Drive下载pdf文件

来自分类Dev

使用Google Drive API获取文件大小

来自分类Dev

Google drive api - com.google.api.services.drive.Drive.files() - None of the File objects have permissions?

来自分类Dev

Google Drive SDK和Unicode文件名

来自分类Dev

在Android中使用“文件文件=新文件(文件名)”将文件保存到何处

来自分类Dev

如何在Google Drive V3 PHP中更新文件

来自分类Dev

命令行:如果文件名已经存在,则使用新文件名创建文件

来自分类Dev

命令行:如果文件名已经存在,则使用新文件名创建文件

来自分类Dev

Google云端硬盘api范围和文件访问权限(驱动器vs drive.files)

来自分类Dev

使用文件名读取最新文件包含python中的字符串

来自分类Dev

PHP使用子目录作为新文件名重命名所有文件

来自分类Dev

使用 Google Drive API 时不显示上传的文件

来自分类Dev

使用python-watchdog监视文件夹,但是当我重命名文件时,我无法找到查看新文件名的方法

来自分类Dev

如何使用Android Google Drive SDK将文件上传到Google Drive文件夹

Related 相关文章

  1. 1

    使用GAS克服Google Drive API Drive.Files.insert()方法的最大文件大小限制

  2. 2

    匿名 Google Drive 上传创建新文件夹

  3. 3

    在Google Drive API的v3版本中通过drive.files.copy转换通过nodejs使用API将Word文档转换为Google文档

  4. 4

    使用Google Drive API SDK从Google Drive删除文件

  5. 5

    使用Google Drive API在指定的Google Drive中上传文件

  6. 6

    使用Google Advanced Drive服务使用Apps Script在文件夹中创建新文件

  7. 7

    检查文件名是否存在并在Google脚本中更新文件名

  8. 8

    如何根据部分文件名使用 Google Script 自动移动 Google Drive 中的文件?

  9. 9

    使用Files.copy()选择文件名

  10. 10

    Iterate Through Folders/Subfolders/Files in Google Drive

  11. 11

    List of un syncable files in Google Drive

  12. 12

    List of un syncable files in Google Drive

  13. 13

    使用带有原始文件名和扩展名的Google Drive API下载

  14. 14

    Google Drive Java Api-文件夹中的更新文件。

  15. 15

    从新文件自动创建新的 Google Drive 文件夹

  16. 16

    使用wget从Google Drive下载pdf文件

  17. 17

    使用Google Drive API获取文件大小

  18. 18

    Google drive api - com.google.api.services.drive.Drive.files() - None of the File objects have permissions?

  19. 19

    Google Drive SDK和Unicode文件名

  20. 20

    在Android中使用“文件文件=新文件(文件名)”将文件保存到何处

  21. 21

    如何在Google Drive V3 PHP中更新文件

  22. 22

    命令行:如果文件名已经存在,则使用新文件名创建文件

  23. 23

    命令行:如果文件名已经存在,则使用新文件名创建文件

  24. 24

    Google云端硬盘api范围和文件访问权限(驱动器vs drive.files)

  25. 25

    使用文件名读取最新文件包含python中的字符串

  26. 26

    PHP使用子目录作为新文件名重命名所有文件

  27. 27

    使用 Google Drive API 时不显示上传的文件

  28. 28

    使用python-watchdog监视文件夹,但是当我重命名文件时,我无法找到查看新文件名的方法

  29. 29

    如何使用Android Google Drive SDK将文件上传到Google Drive文件夹

热门标签

归档