Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing Google Sheets to "Republish Now"

Google Sheets allows you to publish the data to the web as a .XLS file or .CSV etc. I have a system where I edit the spreadsheet and when I'm finished I run a script which downloads the .csv file and processes it for use on our website.

The problem is that the .csv file produced is sometimes a few minutes out of date which means every time I finish editing I need to hit the "publish to web"->"republish now" button before running my script. This is becoming a chore for me and not acceptable to ask my other users to remember.

I need to either make my command-line-script automatically tell Google to republish, or find another way to get the current data out of my spreadsheet.

like image 948
Christopher Gutteridge Avatar asked Jan 13 '12 15:01

Christopher Gutteridge


2 Answers

I found a solution; using credentials to log into google and download a sheet gives you an entirely live version, and can easily be automated. More details in my blog: http://blogs.ecs.soton.ac.uk/webteam/2012/02/08/getting-live-google-spreadsheets/

like image 110
Christopher Gutteridge Avatar answered Oct 30 '22 07:10

Christopher Gutteridge


Google Sheets now has a setting to republish automatically on changes, but another thing that seems to be happening in my use is that an old version is getting cached by something on Google's side.

Adding a new parameter to the end of the URL (e.g. &foo=12312) works to avoid the cache and return the current version. If you're running from a script, just use the current time or a randomly generated number as the parameter value.

Edit: currently (January 2020) this doesn’t resolve the issue 100% of the time. I haven’t experimented to see if it still helps when using the API isn’t an option.

like image 43
pidge Avatar answered Nov 17 '22 04:11

pidge