I thought that in this case, the endpoint might be https://docs.google.com/spreadsheets/d/{spreadsheetId}/gviz/tq?tqx=out:csv&tq={Query}
instead of https://spreadsheets.google.com/tq?tqx=out:csv&tq={Query}&key={SheetID}
.
And, when you want to request the endpoint using your access token, how about the following request?
GET https://docs.google.com/spreadsheets/d/{spreadsheetId}/gviz/tq?tqx=out:csv&tq={Query}&access_token={your access token}
or
GET https://docs.google.com/spreadsheets/d/{spreadsheetId}/gviz/tq?tqx=out:csv&tq={Query}
Request header --> Authorization: Bearer {your access token}
When these are converted to the curl command, it becomes as follows.
curl -L "https://docs.google.com/spreadsheets/d/{spreadsheetId}/gviz/tq?tqx=out:csv&tq={Query}&access_token={your access token}"
or
curl -L -H "Authorization: Bearer {your access token}" "https://docs.google.com/spreadsheets/d/{spreadsheetId}/gviz/tq?tqx=out:csv&tq={Query}"
Note:
- When you use the access token, please include one of the following scopes.
https://www.googleapis.com/auth/spreadsheets
https://www.googleapis.com/auth/drive.readonly
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.file
- In this case, it is required to create a Spreadsheet using the access token with the scope of
https://www.googleapis.com/auth/drive.file
. When the existing Spreadsheet is accessed using the access token of this scope, an error like 404 occurs. Please be careful about this.
When https://www.googleapis.com/auth/spreadsheets.readonly
is used as the scope, a 401 error occurs. Please be careful about this.
References: