加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Google API Ruby Client(gem)错误`未初始化的

发布时间:2020-12-17 04:04:56 所属栏目:百科 来源:网络整理
导读:这肯定让我困惑了几个小时.我已经 bootstrapped my application as detailed by Baugues到OAuth2的身份验证工作,我只是在会话#create(回调)动作中测试.这是一些代码: class SessionsController ApplicationController def create @auth = request.env["omni
这肯定让我困惑了几个小时.我已经 bootstrapped my application as detailed by Baugues到OAuth2的身份验证工作,我只是在会话#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

在进行身份验证时,上述逻辑在回调方法中执行 – 出于此粗略测试的目的,渲染create.html.erb.我已经注释掉了刚刚回显到视图中的@result实例变量.

但是,Google :: APIClient :: UploadIO.new(“foo”,“text / plain”)会触发未初始化的常量Google :: APIClient :: UploadIO.我已经挖掘了这个gem的来源,并且gem的media.rb中需要UploadIO类.

建议和帮助表示赞赏!

参考:

> http://code.google.com/p/google-api-ruby-client/
> https://developers.google.com/drive/v1/reference/files/insert
> https://developers.google.com/drive/examples/ruby#saving_new_files

解决方法

检查您的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'

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读