2021年3月20日星期六

How to retrieve a Google Sheet with a JS fetch() call?

So I have been doing several hours of searching on this and cannot find anything that works with the current Google Sheets API (v4) in a browser. I can 100% get data through Postman and even a browser address bar. I have a public Google Spreadsheet. I have an API Key. I can successfully return all of the row data.

As soon as I try to do so in a browser extension, I get nothing.

Is anyone aware of how to configure a JavaScript fetch() call to get a successful return on a public Google Spreadsheet? No editing, no deleting. Just a GET.

Here's what I'm trying but isn't working:

var url = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${sheetId}?key=${key}`    var response = await fetch(url, {          method: "GET",          mode: "no-cors",          headers: {              "Host": "sheets.googleapis.com"          }      });  

Two things I noticed:

  1. If mode wasn't set to no-cors in the fetch() I would get a NetworkError
  2. In Postman if there wasn't a Host header, I would get an error response
https://stackoverflow.com/questions/66728360/how-to-retrieve-a-google-sheet-with-a-js-fetch-call March 21, 2021 at 10:42AM

没有评论:

发表评论