Google api version version 25 is giving followin e

2019-04-17 10:33发布

问题:

Although I am specifying valueInputoption but still i am getting this error. I followed google sheet`s quickstart.js tutorial for authentication.

  function appendData(auth) {

    var sheets = google.sheets('v4');
    values: [ ["Void", "Canvas", "Website"], ["Paul", "Shan", "Human"] ];

     var body = {
    values: this.values
   };
  sheets.spreadsheets.values.append({
   auth: auth,
   spreadsheetId: '13QPQj1Ot0oBJms2eQzrKahwzGt13JxQkqf54j2zk3jI',
   range: 'Sheet1!A2:B', //Change Sheet1 if your worksheet's name is 
   //something else
   valueInputOption: "USER_ENTERED",
   insertDataOption: 'INSERT_ROWS',
  resource: body

      }, (err, response) => {
   if (err) {
  console.log('The API returned an error: ' + err);
  return;
} else {
    console.log("Appended");
  }
});
}

回答1:

Looks like it might be an issue with v^25.0. Switching to v24.0.0 resolved the issue for me:

... "dependencies": { "googleapis": "24.0.0", }, ...

https://gist.github.com/iaincollins/43302ea047d4a77e6605350598d160c1



回答2:

First thing I suggest that you change is to use apostrophe (') instead of double quotes ("). If that doesn't work check my snippet taken from Sheets API NodeJS Quickstart combining it with the concepts of spreadsheets.values.append:

function appendToSheet(auth) {
    var sheets = google.sheets('v4');
    sheets.spreadsheets.values.append({
      auth: auth,
      spreadsheetId: 'MY_SPREADSHEET_ID',
      range: 'rawSheet!A:B',
      valueInputOption: 'USER_ENTERED',
      insertDataOption: 'INSERT_ROWS',
      resource: {
          "range": "rawSheet!A:B",
          "values": [
             [ "Conor","McGregor"]
          ]
      }
    });
}

Let me know if it works for you.