I would like to write a script in Ruby (using the gdata gem, rest-client gem or just straight Net::HTTP) to authenticate with my google docs using gmail-userid/password, and then download a list of private documents and documents.
The GData documents guide makes it clear how to get publicly visible documents, but it's not clear how I can authenticate myself in my script to get access to private documents. The authentication methods they specify all seem to require human intervention, either with a Capcha or some form of OAuth/OpenID redirection.
Is there some way to access my private documents with just a userid/password combination? Or perhaps that along with an API key? If so, can anybody show me how to do this?
So, sometimes giving up, moving on to something else, and coming back with a fresh mindset can do wonders. I started looking at this again this morning and within a couple of hours got it working.
I ditched OAuth because the Ruby OAuth gem seems to be centered around web based applications. I started poking around in Google Data on Rails, and using ClientLogin, it was no problem getting authenticated, and as far as I can tell, you don't get CAPTCHA requests unless you enter in the wrong credentials... or at least I haven't otherwise seen any yet.
Here is a simple code snippet to export a spreadsheet file:
require 'gdata/client'
require 'gdata/http'
require 'gdata/auth'
client = GData::Client::Spreadsheets.new
client.clientlogin('username', 'password')
test = client.get("http://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="resource_ID"&fmcmd&exportFormat=xls")
file = File.new("spreadsheet.xls", "wb")
file.write test.body
file.close
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With