无法使用Google表格API创建新的电子表格

Gre*_*reg 1 node.js google-drive-api google-sheets-api

我正在使用googleapis软件包创建新的Google电子表格,但它失败了.当我在Google API文档中使用基于网络的工具时,相同的请求也有效.

Google.prototype.createSheet = function(filename, callback) {
    var services = google.sheets('v4');
    services.spreadsheets.create({
      properties : {title:filename},
      auth       : this.auth
    }, function(err,response) {
      if( err ) {
        console.log('Error : unable to create file, ' + err);
        return;
      } else {
        console.dir(response);
      }
    });
}
Run Code Online (Sandbox Code Playgroud)

结果,

错误:无法创建文件,错误:收到无效的JSON有效负载.未知名称"properties":无法绑定查询参数.在请求消息中找不到字段"属性".

我也尝试使用属性名称"资源"而不是"属性",因为我发现在其他工作表端点.这也没有用,但是当我调试googleapis代码时,会产生不同的错误消息,但也会产生不同的API请求.

错误:无法创建文件,错误:收到无效的JSON有效负载."电子表格"中的未知名称"标题":找不到字段.

我还尝试使用Drive API创建文件但没有成功.

Gre*_*reg 5

哇.原来答案是我的两个实验的混合.封装资源块内的属性.

Google.prototype.createSheet = function(filename, callback) {
    var services = google.sheets('v4');
    services.spreadsheets.create({
      resource : {properties:{title:filename}},
      auth       : this.auth
    }, function(err,response) {
      if( err ) {
        console.log('Error : unable to create file, ' + err);
        return;
      } else {
        console.dir(response);
      }
    });
}
Run Code Online (Sandbox Code Playgroud)

我没有在Google API文档中看到任何表明这是发送请求的正确方法,因此即使它有效,这也不是很令人欣慰.