[筆記] Google SpreadSheet API V4 改版 – 當作前端開發所需的 API 來源

章節連結

Google SpreadSheet 的 API 已經於 2021 年 的八月正式從 v3 升級成 v4。換言之,在 [筆記] 將 Google Sheet 變身成 API Server ( 匯入 JSON 和輸出 JSON ) 所提及的方法來取得 JSON 回傳值,也就一併失效了。這篇筆記下如何取得用新的 api 取值,以及一些改動。
google-sheet-as-an-api-server-import-json


申請方法

1. 進入 Google Cloud Platform ( GCP ) ,新增一個專案 ( 如果你沒有任何專案的話 )
spreadsheet-api-v4-1
2. 點選側邊攔,選擇 API 和服務,並點選 +API 和服務,開啟 Google Sheets API
spreadsheet-api-v4-23. 點選左側的憑證,再按下上方的 +建立憑證 ( API 金鑰 )
spreadsheet-api-v4-3 4. 點選「限制金鑰」,並控制能存取的 API,也就是方才新增的「Google Sheets API
spreadsheet-api-v4-4
5. 開啟你的目標 Google Sheet,將其「共用設定」改為「任何知道這個連結的網際網路使用者都能查看 – 檢視者」
6. Google Sheet 的 id 可以在網址列取得:

https://docs.google.com/spreadsheets/d/<Google Sheet ID>/edit#gid=0
7. Google Sheet v4 的 API 格式為:

https://sheets.googleapis.com/v4/spreadsheets/<Google Sheet ID>/values/<試算表的分頁名>?alt=json&key=<API KEY>


參考資料

1. [docs] Google Sheet API v3 升 v4
2. How to migrate google sheets API v3 to google sheets Api v4

按讚加入粉絲團

延伸閱讀