Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching a Google Sheet csv file yields CORS error

I try to tech data from a Google spreadsheet using this code

function init() {
    Papa.parse(public_spreadsheet_url, {
      download: true,
      header: true,
      complete: showInfo
    })
  }

This yields the following CORS error:

Access to XMLHttpRequest at 'link to shared Google Sheet CSV' from origin 'my domain' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

like image 777
jak Avatar asked Dec 22 '22 17:12

jak


2 Answers

It looks like Google has changed something in the last few days. This is preventing sites from linking direct to a Google Sheet. You will need to cache the file using a remote service to get around the CORS issue.

A service like https://cors-anywhere.herokuapp.com will do the job but there are request limits.

like image 100
John Croucher Avatar answered Jan 22 '23 14:01

John Croucher


I had the same problem, I decided to download the tsv from google sheets and put it in my project folder, but I continued getting the CORS error when I use papa parse to parse a tsv file in my project, so I think it's a papa parse issue, not google sheets. I think it might be this commit: https://github.com/mholt/PapaParse/commit/018f5dfe419c68f4f084df3d4452190cd501a74a

like image 23
leucotic Avatar answered Jan 22 '23 14:01

leucotic