-
Notifications
You must be signed in to change notification settings - Fork 444
The new PapaParse solution yields "No 'Access-Control-Allow-Origin' header" error #189
Comments
I hired a super dev who helped me through that error, enabling successful sheet access via Google API v4 (still using Papa Parse as an aid). I can post solution tomorrow.
Google stopped placing CORS headers on CSV. (4 days after I did the recommended update, seemingly successfully. Quite a shock to go from “YAY!” to nothing working at all, four days later.)
- Get a Google API key. Instead of the share ID, use the sheet URL ID.
- Consult Google API migration docs for how to structure the HTTP request url.
- And then use Papa Parse to deal with returned array of arrays.
I can post sample working code tomorrow. (I’ll check with dev to see if he wants to be credited.)
------
UPDATE: GitHub notes: "Email replies do not support Markdown." So I've pasted the working solution in the next comment.
|
Check to see if you have further references to tabletop. For instance, if you have:
You can replace that with:
Of course, remove the tabletop script, and add the PapaParse script in your HTML file.
You might not need the parse/unparse above, but it worked for me as a direct drop-in to my code. I'll credit the dev who wrote the functions, with his permission. (I've written to ask.) He relied on this Google Sheets API migration documentation: Update: Dev responds:
|
Thanks so much for solving this one. I've been tearing my hair all afternoon over it. My new web app broke only two weeks in, but only for some sheets. No way to know it was down to a Google policy change! |
This works for me, thanks! I had to remember to go into the sheet's sharing options and make it so anyone with the link can view before it worked, and it took me far too long to figure out that was why I was getting permissioned denied errors. |
Thank you!! I updated the README with a link to this issue. |
By the way, getting the API key sounds easy, but it is legitimately confusing. This quirky video covers most of the steps: (Substitute Google Sheets API for the YouTube Data API v3.) I found there was a bit of confusion at the end; it didn't grant me a key right away (as the video shows on the YouTube side). I don't remember exactly what finally did the trick. Clarifying comments on that step are welcome. (The other hard or non-intuitive parts are figuring out in advance what you’ll be charged... and figuring out how to request upgrades to various imposed limits... and figuring out how to protect your key.) |
Is it still possible to access the Google Sheet without needing OAuth? I attempted to to reproduce @mroswell 's solution but in order to get an API key I need OAuth. This would be very frustrating for my app and I'm hoping to avoid it. Thanks! |
(Ah, that is the confusing part that I alluded to above. #189 (comment)). I think I just entered the required dialog, and saved without setting up OAuth, and it worked. If that works for you, can you document, and we can add those steps in addition to the YouTube video I referenced to the documentation. |
I did the same. At https://console.developers.google.com/apis/credentials use +Create Credentials to create an API Key, restrict it appropriately (taking these comments into account) , copy and use it in your code. |
Documentation that worked for me: I hope this helps! |
I'm able to get API-free no-cors-issues access to the JSON of a public google sheet using the following url string: crucially the doc_id is taken from the sharing screen, not from the "Publish to web" screen. |
I think that's using Google API v3, instead of 4. Not sure: I'm looking at: https://developers.google.com/sheets/api/guides/migration#v4-api_9 (No mention of the "od6" in either documentation version -- though I've seen that before in the real world -- but I don't feel confident that this will work after September.) |
But it definitely is weird. My original code that accesses 'published to the web' Sheets without an API key now works again, having been broken for the last couple of weeks! Maybe someone at Google read this thread and realised that the requiring a key for programmatic access to users' Google Drive data that is meant to be in the public domain is more Apple-like than Google-like. Meanwhile I now have two versions of my web app with and without API key and I'm not sure which to release! I'd much prefer users to be able to use my app access their sheets without having to sign up for an API key. |
The comments in this thread helped me immensely, so thanks everyone! FYI I got my app working by using a Google Sheets API key securely on the server-side with Netlify functions: https://github.com/vdsabev/95-percent/blob/master/api/questions.js - this way I can even massage the data to suit my needs and there's no longer need for Papa Parse. Ironically, the most difficult part about this was navigating the Google API console to create a key. |
Now that tabletop definitely doesn't work anymore, I tried to use the Papa Parse alternative. But I can't see a way to create an API Key for an existing Google Sheets file that already has an Apps Script project (associated with the Google Cloud Platform Default project). How do I create an API Key for a file and associated project that already exist? |
This is miracle! Thanks you a lots mroswell! I having trouble that I misunderstand this code at first glanced.
Well don't be a dumb guy like me. XD |
The solution @willismonroe mentions unfortunately doesn't seem to work anymore because the v3 API has been shut down. |
Using the example code at https://github.com/jsoma/tabletop/blob/master/examples/simple/no-tabletop.html yields the following error when I try to load a spreadsheet:
Access to XMLHttpRequest at 'https://doc-0s-4k-sheets.googleusercontent.com/pub/l5l039s6ni5uumqbsj9o11lmdc/bj8mlpr717s5u5a0ves5ooppes/1593142745000/112192102762685134803/*/e@2PACX-1vQB-VAHmJgZQ00hlOGySWx8kd0Cq4z7o1V47juQc3PcTHkCuCNNmd9YxHZW4cnzDjA71UH0eL85VE5i?gid=0&single=true&output=csv' (redirected from 'https://docs.google.com/spreadsheets/d/e/2PACX-1vQB-VAHmJgZQ00hlOGySWx8kd0Cq4z7o1V47juQc3PcTHkCuCNNmd9YxHZW4cnzDjA71UH0eL85VE5i/pub?gid=0&single=true&output=csv') from origin 'https://learning-web.github.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
The text was updated successfully, but these errors were encountered: