无法使用Google表格API创建新的电子表格 [英] Unable to create a new spreadsheet with the Google Sheets API

查看:264
本文介绍了无法使用Google表格API创建新的电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用googleapis软件包来创建新的Google Spreadsheet,并且失败。当我在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 (错误){
console.log('错误:无法创建文件,'+ err);
return;
} else {
console.dir(response);
}
});

$ / code>

结果,

< blockquote>

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


我也尝试使用属性名称资源而不是属性,因为我发现在其他工作表端点。这也不起作用,但是当我调试googleapis代码时,导致了不同的错误消息,但也导致了不同的API请求。


错误:无法创建文件,错误:收到无效的JSON有效内容。
'电子表格'中的未知名称title:无法找到字段。


Drive API 未成功

解决方案

DIV>

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

  Google.prototype.createSheet =函数(文件名,回调){
var services = google.sheets('v4 );
services.spreadsheets.create({
resource:{properties:{title:filename}},
auth:this.auth
},function(err,response){
if(err){
console.log('错误:无法创建文件,'+ err);
return;
} else {
console.dir响应);
}
});
}

我没有看到任何 Google API文档中指出这是发送请求的正确方式,所以即使它有效,这也不是很令人欣慰。


I'm using the googleapis package to create a new Google Spreadsheet and it fails. The same request works when I use the web-based tools in the Google API documentation.

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);
      }
    });
}

The result,

Error : unable to create file, Error: Invalid JSON payload received. Unknown name "properties": Cannot bind query parameter. Field 'properties' could not be found in request message.

I've also tried using a property name of "resource" instead of "properties" because I found that in other sheets endpoints. That also didn't work but resulted in both a different error message but also a different API request when I debug the googleapis code.

Error : unable to create file, Error: Invalid JSON payload received. Unknown name "title" at 'spreadsheet': Cannot find field.

I've also tried creating the file using the Drive API without success.

解决方案

Wow. Turns out the answer is a hybrid of my two experiments. Encapsulating the properties inside of a resource block.

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);
      }
    });
}

I don't see anything in the Google API documentation that indicates that this is the right way to send the request so this isn't very comforting even though it's effective.

这篇关于无法使用Google表格API创建新的电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆