Google API Ruby客户端(gem)错误`未初始化的常量Google :: APIClient :: UploadIO`

Mic*_*lva 4 ruby ruby-on-rails oauth-2.0 google-drive-api

这肯定让我困惑了几个小时.我已经通过Baugues详细介绍了我的应用程序,以便通过OAuth2进行身份验证,并且我只是在session#create(回调)操作中测试.这是一些代码:

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
Run Code Online (Sandbox Code Playgroud)

在验证时,在该callback方法中执行上述逻辑- 为了该粗略测试的目的,将其呈现出来create.html.erb.我已经注释掉了@result刚刚回显到视图中的实例变量.

但是,当它显然不应该Google::APIClient::UploadIO.new("foo", "text/plain")触发uninitialized constant Google::APIClient::UploadIO时.我已经通过这种宝石的来源挖和UploadIO类是requiredmedia.rb创业板.

建议和帮助表示赞赏!

参考:

Ste*_*zyl 8

检查您的Gemfile.lock以查看它实际使用的google-api-client版本.当我执行相同的步骤时,默认情况下它看起来像0.3.0,可能是由于google-omniauth-plugin稍微落后于它的依赖.0.3.0没有媒体支持.

尝试将Gemfile更改为

gem 'google-api-client', '~> 0.4.3', :require => 'google/api_client'
Run Code Online (Sandbox Code Playgroud)

并重新运行'bundle install'以强制它使用更新版本.