Access Google spreadsheet API without Oauth token

我与影子孤独终老i 提交于 2019-12-07 09:01:24

问题


I've read google spreadsheet documentation https://developers.google.com/sheets/api/guides/authorizing And it says, that if document is public, you don't need Oauth 2.0 and API key is sufficient. I'm trying to do a test request with hurl and api key as parameter.it, but it still gives me error, that I need to use Oauth, any thoughts?

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

Response: "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"}


回答1:


API key is not enough. You're trying to use spreadsheets.values.append which requires OAuth authorization:

Authorization Requires one of the following OAuth scopes:

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).

Note it says OAuth.




回答2:


In my case I need to publish content from a Google Spreadsheet to a web page. My workaround consists in use the HTTP GET call

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

using the javascript object XMLHttpRequest In this solution you only have to use the API key



来源:https://stackoverflow.com/questions/48747530/access-google-spreadsheet-api-without-oauth-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!