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
类是required
在media.rb
创业板.
建议和帮助表示赞赏!
检查您的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'以强制它使用更新版本.
归档时间: |
|
查看次数: |
5650 次 |
最近记录: |