Ruby: Google Drive – Error=BadAuthentication (GoogleDrive::AuthenticationError) Info=InvalidSecondFactor
I’ve been using the Google Drive gem to try and interact with my Google Drive account and almost immediately ran into problems trying to login.
I started out with the following code:
require "rubygems" require "google_drive" session = GoogleDrive.login("email@example.com", "mypassword")
I’ll move it to use OAuth when I put it into my application but for spiking this approach works. Unfortunately I got the following error when running the script:
/Users/markneedham/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/google_drive-0.3.10/lib/google_drive/session.rb:93:in `rescue in login': Authentication failed for firstname.lastname@example.org: Response code 403 for post https://www.google.com/accounts/ClientLogin: Error=BadAuthentication (GoogleDrive::AuthenticationError) Info=InvalidSecondFactor from /Users/markneedham/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/google_drive-0.3.10/lib/google_drive/session.rb:86:in `login' from /Users/markneedham/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/google_drive-0.3.10/lib/google_drive/session.rb:38:in `login' from /Users/markneedham/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/google_drive-0.3.10/lib/google_drive.rb:18:in `login' from src/gdoc.rb:15:in `<main>'
It will then pop up with a password that we can use to login (I have revoked this one!):
We can then use this password instead and everything works fine:
require "rubygems" require "google_drive" session = GoogleDrive.login("email@example.com", "tuceuttkvxbvrblf")