Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby script to download private google docs

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?

like image 883
Jay Godse Avatar asked Feb 11 '11 18:02

Jay Godse


1 Answers

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  
like image 185
user613910 Avatar answered Oct 16 '22 05:10

user613910