我想代表我的应用程序的用户使用 GViz(类似 SQL 的查询语言)和 Google API 查询 Google 电子表格,但是,在 Sheets API 中(https://developers.google.com/sheets/api/指南/概念)我找不到这样的端点。
我知道我可以这样做:https://spreadsheets.google.com/tq?tqx=out:csv&tq={Query}&key={SheetID} 但我不知道如何使用用户对其进行身份验证令牌。它不同于 API 端点身份验证 (https://sheets.googleapis.com/v4/spreadsheets)
有什么办法吗?
我正在寻找通过 Google Visualization Api 查询语言(或其他查询语言)使用 Google API 过滤数据的任何方法,获取带有过滤结果的 json/csv。我只有用户访问令牌。令牌具有适当的范围。
我认为在这种情况下,端点可能是
https://docs.google.com/spreadsheets/d/{spreadsheetId}/gviz/tq?tqx=out:csv&tq={Query}
而不是https://spreadsheets.google.com/tq?tqx=out:csv&tq={Query}&key={SheetID}
。
而且,当您想使用访问令牌请求端点时,以下请求怎么样?
GET https://docs.google.com/spreadsheets/d/{spreadsheetId}/gviz/tq?tqx=out:csv&tq={Query}&access_token={your access token}
或
GET https://docs.google.com/spreadsheets/d/{spreadsheetId}/gviz/tq?tqx=out:csv&tq={Query}
Request header --> Authorization: Bearer {your access token}
将这些转换成curl命令后,就变成了如下
curl -L "https://docs.google.com/spreadsheets/d/{spreadsheetId}/gviz/tq?tqx=out:csv&tq={Query}&access_token={your access token}"
或
curl -L -H "Authorization: Bearer {your access token}" "https://docs.google.com/spreadsheets/d/{spreadsheetId}/gviz/tq?tqx=out:csv&tq={Query}"
https://www.googleapis.com/auth/spreadsheets
https://www.googleapis.com/auth/drive.readonly
https://www.googleapis.com/auth/drive
使用
https://www.googleapis.com/auth/spreadsheets.readonly
作为作用域时,会出现401错误。请注意这一点。