Of course, here is the basic version of what I'm doing:
require 'mechanize' agent = Mechanize.new page = agent.get "https://docs.google.com" form = page.forms.first form.Email = "your_username" form.Passwd = "your_password" page = agent.submit form test = agent.get "google_download_url_goes_here" puts test.body
If you look at test , you will see Java redirect material instead of the xls file.
I did not work on it after a couple of days, but I have a slight feeling that I am getting a redirect because the script is not "correctly" authenticated. The mechanism should handle cookies and redirect, so I think it just should work, but it doesnโt.
UPDATE:
The export URL is a little further on the same page in the documentation that you referenced in your comment. The URL for exporting the spreadsheet is as follows:
http://spreadsheets.google.com/feeds/download/spreadsheets/Export?key= "document_resource_id_goes_here" & exportFormat = xls
You should be able to connect this in a browser and download the file (if you are logged in, of course). The document resource identifier is the only unique key for any document that you work with, it can be manually inserted into the URL for testing in the browser.
However, I am sure that none of these API URLs will work in the script unless it handles authentication correctly as requested by Google. I'm not quite sure what I'm looking for, but using Wireshark to sniff out packages, I see some errors when using the script that I don't get when using my browser. These errors occur when the server and script exchange information about a certificate. Anyway, I look again at the pearl of OAuth and think that I am beginning to understand this better.
If you go here:
http://googlecodesamples.com/oauth_playground/
You can play with OAuth stuff, this is crazy how it works. You are requesting a request token with a set of parameters that must be "fair." It sends a request token, which is then used to link to the login page where you enter your Google credentials (as with manual work with Google docs). As soon as your credentials are verified, he will ask you to provide permission for the request token. The request token is updated to the access token, and then returned back to your script, and you can start working with the rest of the API by specifying this access token ... it seems unnecessary, but I'm not a security expert.
Here is what I hope to do:
Find out how to use the OAuth Ruby gem to request and send tokens to Google.
Use the Engine to clear the Google login page and enter the credentials as soon as I can send him the request token he wants
Use the Engine to click the "Grant Access" button after submitting my credentials
Then I hope you find that I can actually use the rest of the API to work with files
(Grrr! Learning how to format text correctly on this site is just as difficult !! :))