1

I'm trying to receive data from Google Sheet and it was working but currently the fetch keeps failing with the following error.

const url = `https://docs.google.com/spreadsheets/d/e/${id}/pub?gid=${gid}&single=true&output=csv`;
const result = await fetch(url);
const csvText = await result.text();

Error Image

Pooyan Pal
  • 13
  • 4
  • Does this answer your question? [CORS authorization on google sheets API requests](https://stackoverflow.com/questions/28546969/cors-authorization-on-google-sheets-api-requests) – Estradiaz Jun 25 '20 at 05:09

1 Answers1

1

You can solve the CORS issue with a proxy server. In this, you're just required to append the API request URL to a proxy service provider such as, https://cors-anywhere.herokuapp.com/

var url = https://docs.google.com/spreadsheets/d/e/${id}/pub?gid=${gid}&single=true&output=csv;
var proxyUrl = https://cors-anywhere.herokuapp.com/${url};

fetch(proxyUrl)... //Make a request with this proxy url to navigate CORS issue
ABGR
  • 4,631
  • 4
  • 27
  • 49
  • It is working but depends on other site, it will be fail if other site server will be down. – Pooyan Pal Jun 25 '20 at 05:31
  • Yeah but the chances of their downtown is low. Plus when you deploy your code on the server, this problem will not be there anyway. If you want an alternate solution you may consider adding a middle layer, say in node js, which will fetch the data and return to the client. – ABGR Jun 25 '20 at 05:45