写作'时出错使用Google API进入谷歌电子表格

时间:2018-03-20 10:53:13

标签: javascript google-spreadsheet-api

使用的代码

  var values = [
    [
      'value1','value2','value3'
    ]
  ];
   var body = {
    values: values
  };
  gapi.client.sheets.spreadsheets.values.update({
    spreadsheetId: '1Lofhq9R7X5wzGvO7fMViN8D8q1W3fiNxO5jjP7XL_s0',
    range: 'Sheet1!A1:A4',
    valueInputOption:'RAW',
    resource: body
  }).then((response) => {
    var result = response.result;
    console.log(`${result.updatedCells} cells updated.`);
  });

显示错误

    {
      "error": {
        "code": 400,
        "message": "Invalid JSON payload received. Unknown name \"valueInputOption\": Cannot bind query parameter. Field 'valueInputOption' could not be found in request message.",
        "status": "INVALID_ARGUMENT",
        "details": [
          {
            "@type": "type.googleapis.com/google.rpc.BadRequest",
            "fieldViolations": [
              {
                "description": "Invalid JSON payload received. Unknown name \"valueInputOption\": Cannot bind query parameter. Field 'valueInputOption' could not be found in request message."
              }
            ]
          }
        ]
      }
    }

我已更改了Google电子表格的访问设置,以允许任何拥有该电子表格的人查看和编辑它。只有在我尝试写入电子表格时才会出现此错误,我可以使用其他功能阅读电子表格。

2 个答案:

答案 0 :(得分:1)

没有人知道您列入白名单的域名,因此没有人可以重现您的代码。并且您的电子表格没有Class Data表格,而您在A1:C1而非A1:A4处写错了。

所以我添加了一个工作表并更改了values并尝试了API explorer。结果是200 OK。也许您可以尝试使用'RAW'代替"RAW"或/和values: values代替resource: body

enter image description here

答案 1 :(得分:0)

我错误地指定了API所需的授权范围(在调用更新函数之前)。 使用后错误得到修复 library(dplyr) d %>% mutate_at(2:3, funs(. > 0)) # A B C #1 1 FALSE FALSE #2 1 TRUE TRUE 代替 https://www.googleapis.com/auth/spreadsheets

相关问题