HTTP Google Sheets API v4 how to access without OAuth 2.0?

前端 未结 2 1769
小鲜肉
小鲜肉 2020-12-15 04:58

my idea is to create a google sheet, make it public and then access it from my work computer linux/bash to read/write values on a daily basis.

i have a public goog

相关标签:
2条回答
  • 2020-12-15 05:29

    Another approach is to share the sheet with a Google Cloud service account, and then use the service account to authorize with the API client. If the document is public you do not need to share it.

    Instructions on creating a service account and reading a Google doc, which should also apply to sheets https://www.futurice.com/blog/read-goog-doc-using-service-account

    0 讨论(0)
  • 2020-12-15 05:46

    All Google APIs require that you create a project on [Google developer console1 and identify yourself and your application, even to access public data. Since you have set the sheet to public you can just go to google developer console and create a public api key remember to active the google sheets api. Then just add key=[YourKey] as a parameter on your request.

    Update Dev console:

    Create project and get key:

    Google developer console -> create a project -> credentials drop down -> API Key

    Enable it:

    Google developer console -> library find sheets enable it.

    Update:

    { "error": { "code": 403, "message": "The request is missing a valid API key.", "status": "PERMISSION_DENIED" } }

    Means that you have not identified yourself to Google. In 2015 Google Start to require that we identify ourselves you cant just use a Google API without telling google who you are. You do that by creating a project on [Google developer console1. Create an API key and use that API key in all of your requests. This only works with Public data.

    https://sheets.googleapis.com/v4/spreadsheets/1F6jh6756xNDlDYIvZm_3TrXb59EFEFHGEC7jdWz-Nx0/values/Sheet1!A1:A3?key=YOurKEY

    Note: With private user data you would need to use OAuth and use either access_token=your token or set the header

    Authorization: Bearer ya29.GlvaBLjrTdsSuSllr3u2nAiC-BOsjvIOE1x5afU3xiafB-FTOdLWDtfabuIMGF1rId5BsZxiTXxrx7VDEtxww4Q1uvW9zRndkfm3I2LZnT1HK2nTWzX_6oXu-NAG.

    An access token is not the same as a API Key.

    0 讨论(0)
提交回复
热议问题