Google Sheet API, 'valueInputOption' is re

2019-05-26 00:01发布

问题:

I want to use Line to transfer data to Google Sheet.

function appendMyRow(userId) {
var request = {
   auth: oauth2Client,
   spreadsheetId: mySheetId,
   range:encodeURI("表單回應 1"),
   insertDataOption: 'INSERT_ROWS',
   valueInputOption: 'USER_ENTERED',
   resource: {
     "values": [
       users[userId].replies
     ]
   }
};
var sheets = google.sheets("v4");
sheets.spreadsheets.values.append(request, function(err, response) {
   if (err) {
      console.log('The API returned an error: ' + err);
      return;
   }
});

The error message is: "The API returned an error: Error: 'valueInputOption' is required but not specified"

part of package.json: "dependencies": { "@line/bot-sdk": "^6.3.0", "express": "^4.16.4", "google-auth-library": "^0.12.0", "googleapis": "^27.0.0", "linebot": "^1.4.1", "request": "^2.88.0" }

What values should be set in valueInputOption? I have tried "RAW", 'RAW', "USER_ENTERED", 'USER_ENTERED'. but still return the same error. Thanks!!!!!

回答1:

I originally believed that there was an error in the API specification for the parameter 'valueInputOption' in revision 20181031. Technically there is in the sense that it is not defined as required.

the discovery spec specifies the valueInputOption parameter location as 'query' which I now realise means it is added as a GET param to the end of the path as opposed to the 'path' location value which indicates that the value is substituted into the path string rather than being appended as a GET param.

You will likely need to modify the path to include this parameter as a GET param as it is required.

ie. for the 'sheets.spreadsheets.values.update' ed-point the spec path should be 'v4/spreadsheets/{spreadsheetId}/values/{range}?valueInputOption={valueInputOption}'

I use Perl so I'm not quite sure how this translates to the NodeJS SDK but it should give you a start.

One solution that worked for another was dropping back to an earlier API Spec version as described at Google api version version 25 is giving followin error: Error: 'valueInputOption' is required but not specified