Sure, here's a 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'll see the Java redirection stuff instead of the xls file.
I haven't worked on it in a couple of days, but I have a slight feeling I'm getting the redirection because the script isn't "properly" authenticated. Mechanize is supposed to handle cookies and redirects so I would think this should simply just work, but its not.
UPDATE:
The export URL's are a little farther down on the same page in that documentation you linked to in your comment. The URL for exporting a spreadsheet looks like this:
http://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="document_resource_id_goes_here"&exportFormat=xls
You should be able to plug that into a browser and download a file (if you are logged in, of course). The document resource id is just the unique key for whatever document you are working with, you can manually paste it into the URL for testing in a browser.
However, I'm pretty sure none of these API URL's will work in a script unless it is properly handling authentication the way Google is asking for. I'm not exactly sure what I'm looking at, but using Wireshark to sniff packets I can see some errors when using a script that I don't get when using my browser. These errors seem to occur when the server and script are exchanging some kind of certificate info. Anyway, I've been looking at the OAuth gem some more and think I am starting to understand it better.
If you go here:
http://googlecodesamples.com/oauth_playground/
You can play around with the OAuth stuff, it's kind of crazy how it works. You ask for a request token with a bunch of parameters that must be 'just' right. It sends the request token which you then use to reference a login page where you enter your Google credentials (as you would when you manually work with Google docs). Once your credentials are verified it asks you to grant permission to the request token. The request token is upgraded to an access token and then passed back to your script and you can then start working with the rest of the API by referencing this access token... seems like overkill, but I'm no security expert.
Here's what I'm hoping to do:
Figure out how to use the OAuth Ruby gem to request and send tokens to Google.
Use Mechanize to scrape the Google login page and enter credentials once I can send it the request token it wants
Use Mechanize to click on the "Grant Access" button once my credentials are submitted
Then hopefully find that I can actually use the rest of the API to work with files
(Grrr! learning how to properly format text on this website is about as difficult!! :))