无需Oauth令牌即可访问Google电子表格API

时间:2018-02-12 13:22:44

标签: google-sheets google-spreadsheet-api google-authentication google-developers-console

我已阅读Google电子表格文档https://developers.google.com/sheets/api/guides/authorizing并且它说,如果文档是公开的,那么您不需要Oauth 2.0和API密钥就足够了。我正在尝试使用hurl和api key作为parameter.it进行测试请求,但它仍然给我错误,我需要使用Oauth,任何想法?

POST https://sheets.googleapis.com/v4/spreadsheets/16woR-nfy6KYBbkQpC2YOT1GzIean8rTzjueUnlzLMiE/values/Sheet1!A1:E1:append?valueInputOption=USER_ENTERED

响应: "error": {"code": 401,"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status": "UNAUTHENTICATED"}

3 个答案:

答案 0 :(得分:2)

API密钥是不够的。您正在尝试使用需要OAuth授权的spreadsheets.values.append

  

授权需要以下OAuth范围之一:

https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/spreadsheets
For more information, see the [Auth Guide](https://developers.google.com/identity/protocols/OAuth2).

请注意OAuth。

答案 1 :(得分:2)

就我而言,我需要将Google Spreadsheet中的内容发布到网页上。我的解决方法是使用HTTP GET调用

  

获取   https://sheets.googleapis.com/v4/spreadsheets/ {spreadsheetId} / values / {range}

使用javascript对象XMLHttpRequest在此解决方案中,您只需使用API​​密钥

答案 2 :(得分:1)

您可以使用以下格式:

  

https://docs.google.com/spreadsheets/d/ {sheetID} / export?format = csv

在用公用表替换sheetID并读取csv文件之后,像在通常选择的编程语言中所做的那样,请为此URL建立URLConnection。

请注意,这仅适用于可读的公共Google电子表格,当您不一定需要执行凭据夹具和精简版时,这是一个小技巧

相关问题