How about this answer?
Issue and workaround:
Unfortunately, in the current stage, "Try this API" cannot be directly used by manually inputting the API key and access token. But in this case, there is a workaround. Please see the below figure.
This is the window of "Try this API". When you see this, you can see the clickable square box at the upper right as shown in the figure. Please click it. By this, you can see the expanded "Try this API" as following figure.
Here, please input the required parameters you want to use. By this, you can see the curl sample as follows.
curl --request POST \
'https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEETID/values/RANGE:append?valueInputOption=USER_ENTERED&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"values":[["sample value"]]}' \
--compressed
By using this command, you can use the API by manually inputting the API key and access token.
But, here, there is an important point. At Google API, the API key cannot be used for the method except for GET method. The API key can use only GET method for the publicly shared contents. Please be careful this. So when you want to use "Method: spreadsheets.values.append" in Sheets API by manually inputting the API key and the access token, please use the access token. Because this method uses the POST method. By this, you can test the API. Also, you can see the required scopes at the official document.
By the way, when you want to use only the API key, you are not required to use --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]'
. And also, when you want to use only the access token, you are not required to use &key=[YOUR_API_KEY]
.
At the expanded "Try this API", you can also see HTTP request and the sample script of Javascript there.
Note:
- When you want to request the Sheets API using the API key, please publicly share the Spreadsheet. By this, the value can be retrieved using the GET method like "Method: spreadsheets.values.get", "Method: spreadsheets.get" and so on.
- When you want to see the method for retrieving the access token, you can see it at the official documents like here, here.
Reference: