This has certainly had me baffled for a couple hours. I've bootstrapped my application as detailed by Baugues to the point that authentication via OAuth2 works and I'm just testing things out in the session#create
(callback) action. Here's some code:
class SessionsController < ApplicationController
def create
@auth = request.env["omniauth.auth"]
@token = @auth["credentials"]["token"]
client = Google::APIClient.new
client.authorization.access_token = @token
service = client.discovered_api('drive', 'v1')
file_content = Google::APIClient::UploadIO.new("foo", "text/plain")
# @result = client.execute(
# :api_method => service.files.get,
# :parameters => { 'id' => 1 },
# :headers => {'Content-Type' => 'application/json'})
end
end
Upon authenticating, the above logic is executed in the callback
method - which for the purpose of this crude test renders out create.html.erb
. I've commented out the @result
instance variable that's just echoed out into the view.
However, Google::APIClient::UploadIO.new("foo", "text/plain")
triggers uninitialized constant Google::APIClient::UploadIO
when it clearly should not. I've dug through the source of this gem and the UploadIO
class is required
in media.rb
of the gem.
Advice and assistance appreciated!
Check your Gemfile.lock to see which version of google-api-client it is actually using. When I went through the same steps, it looks like it settled on 0.3.0 by default, likely due to google-omniauth-plugin being a little behind with its dependency. 0.3.0 doesn't have media support in it.
Trying changing your Gemfile to
gem 'google-api-client', '~> 0.4.3', :require => 'google/api_client'
and rerun 'bundle install' to force it to use the more recent version.
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