gimite / google-drive-ruby Goto Github PK
View Code? Open in Web Editor NEWA Ruby library to read/write files/spreadsheets in Google Drive/Docs.
License: Other
A Ruby library to read/write files/spreadsheets in Google Drive/Docs.
License: Other
I am using contact gem for importing contacts from my google account.
For development env it is woking fine but AWS production env is not working.
How can i solve the issue?
Hi.
Could you please add some examples to this gem? I really don't get from docs how to operate with it. I don't even see how to create a folder :\
Thanks.
It is very important question for me.
Is existing method for read early version of spreadsheet? I need only read operation for it.
Thanks!
Whats the right way to do this ? I am currently uploading a new file in the root folder and then adding it to the required folder. This makes the spreadsheet to show up in the root folder as well as the folder it is added to ? It would have been nice if i could "move" the file to the folder or upload file directly to a folder.
If you run the followin in irb, the irb shell hangs on
require 'do_postgres'
require 'google_drive'
GoogleDrive.login('myaccount','mypass')
However it works fine if we first require google_drive
require 'google_drive'
require 'do_postgres'
GoogleDrive.login('myaccount','mypass')
I'm using rvm, ruby 1.9.2 on a MacOSX 10.5.8 Leopard
Thanks you
It would be great if you could expose a last modified / last edit date/time for spreadsheets.
Currently you can set cell[0,0] to a value and then you get a mysterious error in save(). I suggest the following:
def parse_cell_args(args)
if args.size == 1 && args[0].is_a?(String)
return cell_name_to_row_col(args[0])
elsif args.size == 2 && args[0].is_a?(Integer) && args[1].is_a?(Integer)
if args[0] > 0 && args[1] > 0
return args
else
raise(ArgumentError, "Row/col must be >= 1 but are %d/%d" % [args[0],args[1]])
end
else
raise(ArgumentError,
"Arguments must be either one String or two Integer's, but are %p" % args)
end
end
Following the documentation, I try to update the access persmissions for a worksheet for an user from 'writer' to 'reader'
acl[1].role = 'reader'
But the permission of the sheet stays the same. It seems to me the role provided is not used when actually updating the permissions over the API.
See: https://github.com/gimite/google-drive-ruby/blob/master/lib/google_drive/acl_entry.rb#L46-L48 and https://github.com/gimite/google-drive-ruby/blob/master/lib/google_drive/acl.rb#L73-L82.
Does google expose search via its API? I'd be happy to take a look and do the coding. I'd like to be able to do something like this:
row, col = worksheet.find_first('some text')
Hello,
Is it possible to send a notification email when I upload files to Google Drive with ruby 1.8 and gem "google_drive"?
Hi please tag releases to github when uploading new versions to rubygems. It's useful to see everything that has changed. The bundle gem command can give you a nice Rakefile to automate this out of the box.
Hi there,
I have independently written code to obtain an Oauth2.0 token but upon using session.upload_from_file I get this error response from google:
Token invalid - AuthSub token has wrong scope
Error 401
though I have a good looking access token from google and my requested scope is:
'https://www.googleapis.com/auth/drive.file'
'https://www.googleapis.com/auth/userinfo.email'
'https://www.googleapis.com/auth/userinfo.profile'
To be honest I don't even know why I need the second two urls since all I am doing is uploading to the user's google drive. Any idea which scope I am missing and whether I actually need the email and profile scope?
In case you need to know, on the Google API console website the only service I have enabled is "Google Drive API", and NOT "Google Drive SDK".
I can't find any information in the docs about styling spreadsheets (bold, background color, etc...). Is that planned?
If I try to rename a file via a form_for
1 file = session.file_by_title(@specification.title)
2 if file
3 file.rename(params[:specification][:title])
4 end
On line 1 file is
On line 3
Response code 400 for get https://docs.google.com/feeds/default/private ... : : Invalid request URI
I also tried
file.title = params[:specifications][:title]
What exactly goes wrong?
I'm using Omniauth-google-oauth2 to authenticate a user logging into my app, and I store their token (from [omniauth.auth][credentials][token]. It starts with ya29.blahblahblah. I pass this to the login_with_oauth function, but keep getting this error. How come?
The error is this:
ruby/1.9.1/gems/google_drive-0.3.6/lib/google_drive/file.rb:179:in update_from_io': undefined method
[]' for nil:NilClass (NoMethodError)
Referring to this line:
self.document_feed_entry.css("link[rel='http://schemas.google.com/g/2005#resumable-edit-media']")[0]["href"]
self.document_feed_entry looks well formed but that link is no longer in there.
Maybe Google changed the schema?
I like the new vollection class; it makes the library more intuitive!
Is there a way to upload a local file directly to a collection , i.e. a way to
do something like
collection.upload_from_file(("/path/to/hello.txt", "hello.txt", :convert => false)
Tried to download file with format that differs from upload.
(from readme)
file = session.file_by_title("hello.html")
file.download_to_file("/path/to/hello.pdf")
As result, dowanloaded file with html inside.
As I understand from google api docs I need to form the url like this
https://docs.google.com/feeds/download/documents/Export?docID=id_from_hello_html&exportFormat=pdf&format=pdf
How can I apply(or pass) theese paramenters to dowload method?
I am having 1300 files in my gdrive folder but when i do Collection.files. It returns on 98 files.
require "google_drive"
session = GoogleDrive.login("****@gmail.com", "****")
session.upload_from_string("", "sample")
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/google_drive-0.3.1/lib/google_drive/session.rb:370:in `upload_raw': undefined method `root' for nil:NilClass (NoMethodError)
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/google_drive-0.3.1/lib/google_drive/session.rb:316:in `upload_from_io'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/google_drive-0.3.1/lib/google_drive/session.rb:286:in `upload_from_string'
そのまま空文字列データとしてアップロードするか、GoogleDrive::Errorを投げるかみたいな形だと助かります
My code:
require 'google_drive'
SPREADSHEET_KEY = "..."
session = GoogleDrive.login(ARGV[0], ARGV[1])
worksheet = session.spreadsheet_by_key(SPREADSHEET_KEY).worksheets.first
worksheet.rows[1, 1] = 'hello world'
The error (from the line where I tried to set the cell content):
can't modify frozen Array (RuntimeError)
Am I doing something wrong?
When a worksheet has data in all rows and so finding an empty row is impossible the | 0
clause kicks in and so 0
is returned when in fact I think it should return max_rows
as returning 0 can be dangerous if you are planning on appending to a sheet.
Dear Hiroshi, I have tried your library and it works great. I want to use it to extend SIBA backup utility to support Google Drive.
Your library has all I need, except one thing. I need to get a collection by name and path. For example:
session.collection() # Get the root collection
session.collection("photos") # Get a collection located in root
session.collection("photos/vacation") # Get a sub-collection, using file system path syntax.
session.collection("photos/vacation/2012/may") # Get a deeply located collection
session.collection("photos#summer/winter", "#") # Using "#" character as a separator instead of "/" because we have a collection named 'summer/winter'.
Maybe I missed something and I can do it already with your library? If not, do you think it is worth adding to the library?
ListRow#clear
only empties a line, delete
would remove it so no empty line is left over.
I've looked into the source code but I'm not sure whether there could be a better way than shifting all rows below the deleted one up one row.
When you have 2 spreadsheets
*) Test
*) Test2
calling spreadsheet_by_title with Test doesn't reliably give the first spreadsheet where the title is equal, but can give the second spreadsheet where the title is only part of the name. Probably to do with the old Google Spreadsheets API
The javascript API's show a method on a worksheet class for clearing the contents of a sheet as opposed to deleting the entire sheet. I have not been able to find an implementation of this in Ruby, nor the proper protocol for doing so manually. It would be excellent if this gem supported that operation.
http://googledevelopers.blogspot.jp/2012/09/retiring-google-documents-list-api-v3.html
I haven't looked into Google Drive API, so I'm not sure whether I can switch to it keeping current API of google-drive-ruby. I may introduce incompatible API change, or deprecate the library itself.
Hello.
Now I utilize your product with my biz account, but our company offer me to use multi factor authentication.
I set it, then happened.
/Users/shunter1112/.rvm/gems/ruby-1.9.3-p194/gems/google_drive-0.3.2/lib/google_drive/session.rb:88:in `rescue in login': Authentication failed for Response code 403 for post https://www.google.com/accounts/ClientLogin: Error=BadAuthentication (GoogleDrive::AuthenticationError)
Info=InvalidSecondFactor
from /Users/shunter1112/.rvm/gems/ruby-1.9.3-p194/gems/google_drive-0.3.2/lib/google_drive/session.rb:81:in `login'
thank you for your product, I love it. :)
I currently have a google drive which is 10mb. And when I try to load it in
ws = session.spreadsheet_by_key("my_key").worksheets[0]
a Timeout error is thrown.
Is there a way for getting the spreadsheet to be lazy loaded? Or is it required to load the entire spreadsheet into memory for the api to work?
Is there a special reason, why google-drive does not work with 1.5.2? Does it not work or is it simply not tested? I'm also using fog in the same project, which gives a nice bundler-conflict, as fog depends on '~>1.5.0'.
Standalone google-drive works great&if it is just not tested I'lll be happy to test it with 1.5.2...
cheers
stefan
Currently, a presentation can only be downloaded in the PNG format. Event the text/plain format returns a PNG picture as binary string. The result contains only the first page of the presentation.
Is possibly to implement a download in atleast the PDF-Format with all pages?
Sorry, but I not undestend, how I can save GoogleDrive::Session beetween requests in web applications.
If I remember auth_token in web session and do GoogleDrive.login_with_oauth in every request - it worked.
If I try use GoogleDrive.restore_session - operations not worked.
Can I save GoogleDrive::Session between request for no need login to every request?
Thanks!
Hi!
I've been trying to use this gem with omniauth-google-oauth2 and Devise, basically I'm trying to grant access after the user is redirected to the callback, taking the code parameter which is the authentication code as well. I'm trying this to avoid the user to log in twice from my app, I basically want that after the user log in with Google account they can upload files to Google Drive. I'm trying this with the GoogleDrive.login_with_oauth method but it seems not to be working will appreciate your help!
This is the omniauth callback after login with Google:
def google_oauth2
access_token = request.env["omniauth.auth"]
@user = User.find_for_google_oauth2(access_token, current_user)
authorization_code = params[:code]
client = OAuth2::Client.new(
"SECRETID", "SECRETKEY",
:site => "https://accounts.google.com",
:token_url => "/o/oauth2/token",
:authorize_url => "/o/oauth2/auth")
auth_token = client.auth_code.get_token(authorization_code, :redirect_uri => "http://localhost:3000/users/auth/google_oauth2/callback")
session_drive = GoogleDrive.login_with_oauth(auth_token.token)
p session_drive.files
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.google_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
But once I try to login with the Connect to Google button it comes out this error:
Response code 401 for get https://docs.google.com/feeds/default/private/full?v=3: Token invalid - AuthSub token has wrong scope Token invalid - AuthSub token has wrong scope Error 401
It saids it fails in this line "p session_drive.files" when I try to see if the Drive API is fetching the files.
I tried to find a function which would access the Last Modified
field of a spreadsheet I was working on, but was unable to find it.
I think this would be a great enhancement to the API.
How to update file with a new revision?
Thank's in advance!
this sample code not working:
file = session.file_by_title("#{input_file}")
file.update_from_file "#{input_file}" , {:newRevision => true}
It will be good to have anonymous connection to google drive
I have been using this gem for over a year, but recently Google started to flag my app's login attempts as suspicious, and making the code I wrote using this gem practically useless. Has anyone encountered this issue? How did you overcome it?
I'm trying to write 100 columns, was hoping to get to 1000 rows, but it's timing out at about 35 (which seems slow).
/usr/local/lib/ruby/1.9.1/net/protocol.rb:146:in rescue in rbuf_fill': Timeout::Error (Timeout::Error) from /usr/local/lib/ruby/1.9.1/net/protocol.rb:140:in
rbuf_fill'
from /usr/local/lib/ruby/1.9.1/net/protocol.rb:122:in readuntil' from /usr/local/lib/ruby/1.9.1/net/protocol.rb:132:in
readline'
from /usr/local/lib/ruby/1.9.1/net/http.rb:2562:in read_status_line' from /usr/local/lib/ruby/1.9.1/net/http.rb:2551:in
read_new'
from /usr/local/lib/ruby/1.9.1/net/http.rb:1319:in block in transport_request' from /usr/local/lib/ruby/1.9.1/net/http.rb:1316:in
catch'
from /usr/local/lib/ruby/1.9.1/net/http.rb:1316:in transport_request' from /usr/local/lib/ruby/1.9.1/net/http.rb:1293:in
request'
from /usr/local/lib/ruby/1.9.1/net/http.rb:1307:in send_entity' from /usr/local/lib/ruby/1.9.1/net/http.rb:1096:in
post'
from /usr/local/lib/ruby/gems/1.9.1/gems/google_drive-0.3.2/lib/google_drive/client_login_fetcher.rb:38:in block in request_raw' from /usr/local/lib/ruby/1.9.1/net/http.rb:745:in
start'
from /usr/local/lib/ruby/gems/1.9.1/gems/google_drive-0.3.2/lib/google_drive/client_login_fetcher.rb:32:in request_raw' from /usr/local/lib/ruby/gems/1.9.1/gems/google_drive-0.3.2/lib/google_drive/session.rb:423:in
request'
from /usr/local/lib/ruby/gems/1.9.1/gems/google_drive-0.3.2/lib/google_drive/worksheet.rb:312:in block in save' from /usr/local/lib/ruby/1.9.1/set.rb:222:in
block in each'
from /usr/local/lib/ruby/1.9.1/set.rb:222:in each_key' from /usr/local/lib/ruby/1.9.1/set.rb:222:in
each'
from /usr/local/lib/ruby/gems/1.9.1/gems/google_drive-0.3.2/lib/google_drive/worksheet.rb:283:in each_slice' from /usr/local/lib/ruby/gems/1.9.1/gems/google_drive-0.3.2/lib/google_drive/worksheet.rb:283:in
save'
My code is of this form:
session = GoogleDrive.login("[email protected]", "pwd")
title = "doctitle"+Time.now.to_f.to_s
ss = session.create_spreadsheet(title)
ws = ss.worksheets[0]
ws.max_rows = 2000
ws.max_cols = 200
results= CONN.query(qry)
i = 1
results.each { |row|
if i == 1
j = 0
rows.keys.each { |k|
j = j + 1
ws[i,j] = k
}
end
j = 0
row.values.each { |v|
j = j + 1
ws[i,j] = v
}
}
ws.save
Please help. I would really feel sullied to revert to sending daily csv's.
Hello,
With a gem install google_drive on Ubuntu server 12.04, I have this error :
Building native extensions. This could take a while...
ERROR: Error installing google_drive:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
checking for libxml/parser.h... no
libxml2 is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
extconf.rb failed
Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.
Help me please!
I create a simple ruby script to test the gem. Everything is going ok until i need to change the spreadsheet to other file (cckey). He still get the older one.
The Code:
session = GoogleDrive.login("[email protected]", "******")
spreadsheet = session.spreadsheet_by_key(ARGV[0])
worksheet = spreadsheet.worksheets.first
all_steps = []
worksheet.rows.each do |row|
p row
end
My call
ruby test.rb MY_SPREADSHEET_CODE
I have one my owned document and many shared from other users with same titles. How I can open only my document by title, ignoring shared documents from other users with same title?
Any interest in this? I need for my application and was going to send PR if it's wanted.
upload_from_file is working great for me. However, I've only been able to upload into the account's root directory.
Hi,
I think it wouldn't be nice to have kind of an abstract method which is able to make request to the api with the api_method as parameter. Since the drive api provides a bunch more methods than available in the gem I start wondering how to make use of them in combination with this gem.
For instance I dont want to make calls against the api everytime I need the files of my account. I d rather prefer storing all the files in an array in the database and serialize it. The drive api has a method called changes.list which return changes, so whenever i get something returned i can update my stored array, otherwise just use it from the db, which is much fast than requesting collections or files all the time.
So currently I dont any chance to do it with this gem, but maybe I am wrong?
best,
phil
I think this is the only gem I have with an underscore instead of a hyphen, maybe change that up before main release?
Hey,
is it possible to access the streaming url of a video, which is also used by the google flash player? I would like to link my own flash player to the video.
Thanks in advance!
I am only able to download a document as text/html.
Trying to use:
file.download_to_string(:content_type => "text/plain")
Results in an error message:
Downloading with content type "text/plain" not supported for this file. Specify one of these to content_type: ["text/html"]
(I've got a google document written in markdown and a want it in plain text so I can parse it, however I can only get it in HTML which has everything wrapped in tags.)
More and more people will be moving to Two-step authentication. Currently, connecting to an account with Two-step auth enabled generates an error:
Authentication failed for [email protected]: Response code 403 for post https://www.google.com/accounts/ClientLogin: Error=BadAuthentication
Info=InvalidSecondFactor
@session.upload_from_file("#{Rails.root}/#{path}", name, {:convert => false })
This is the code i'm using to upload a file to google drive.
variable name
contails file name. Uploading to google docs works well. But name of created doc is always "Untitled" no matter whatever string i pass to the method.
I see how to create or retrieve a Collection, and I see how to create a spreadsheet using GoogleDrive#create_spreadsheet
, but is there a way to create a spreadsheet in a particular collection? Or perhaps to move it to a collection after it's been created? Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.