1

I am trying to access a google spreadsheet through php (by adding &output=csv to the link) It seems like google does not want this any more, is this correct? I tried file_get_contents (and yes, allow_url_fopen is turned on,) which results in an error. When using CURL, even when setting a valid user agent (I used Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13) I get a notice that the file has temporarily moved. The link I am using works fine with accessing the spreadsheet from a browser. I tried setting the spreadsheet to public from within google docs, to no avail.

Solutions suggested here, here and here don't seem to work any more. If google does not want me to do this I won't keep trying, but I haven't found anything supporting that. In the comments of some page I read something about gData ZendFramework, but would like to avoid anything that is not deployed to a standard LAMP server.

PS: I am not trying to abuse google by leeching their bandwidth. I wrote a conversion script for csv files, and in addition to file upload for conversion I was hoping to integrate with google docs links.

Community
  • 1
  • 1
DudeOnRock
  • 3,685
  • 3
  • 27
  • 58
  • Is the spreadsheet publically accessible? If not, you need to provide the authentication cookie. Also, when using `curl`, use the `CURLOPT_FOLLOWLOCATION` option to follow the redirect. – Barmar Apr 02 '14 at 18:09
  • The spreadsheet is publicly accessible and when I set `CURLOPT_FOLLOWLOCATION` I get redirected to a google login page (even though the spreadsheet is public). The link works in an incognito window without getting asked to log in. – DudeOnRock Apr 02 '14 at 18:16

1 Answers1

3

Make sure the spreadsheet is publicly accessible, and published to the web by selecting "publish to the web" from the File menu.

Copy the link and view it in your browser to check it works. Then replace /pubhtml at the end of the URL with /export?format=csv&id and voila! Well it worked for me.

See https://productforums.google.com/forum/#!topic/docs/An-nZtjaupU

Dan
  • 1,536
  • 1
  • 10
  • 20