Ruby on rails 3 如何使用omniauth+从Rails 3应用程序访问Google Drive;omniauth谷歌应用程序
我正在尝试使用gem访问googledrive,但没有成功。该gem有一个使用auth登录的选项,但我不知道如何从omniauth获取访问令牌。返回的架构为 这是我的密码 在models/user.rb中Ruby on rails 3 如何使用omniauth+从Rails 3应用程序访问Google Drive;omniauth谷歌应用程序,ruby-on-rails-3,omniauth,google-drive-api,Ruby On Rails 3,Omniauth,Google Drive Api,我正在尝试使用gem访问googledrive,但没有成功。该gem有一个使用auth登录的选项,但我不知道如何从omniauth获取访问令牌。返回的架构为 这是我的密码 在models/user.rb中 def self.create_with_omniauth(auth, role = 'user') create! do |user| user.email = auth['info']['email'] user.first_name = auth['info']['f
def self.create_with_omniauth(auth, role = 'user')
create! do |user|
user.email = auth['info']['email']
user.first_name = auth['info']['first_name']
user.last_name = auth['info']['last_name']
user.google_token = auth['credential']['token']
user.google_secret = auth['credential']['secret']
user.role = Role.where(:account_type => role).first_or_create
end
end
在控制器/会话中\u coontroller.rb
auth = request.env["omniauth.auth"]
email = auth['info']['email']
user = User.find_by_email(email) || User.create_with_omniauth(auth)
def index
session = GoogleDrive.login_with_oauth(current_user.google_tocken)
for file in session.files
@docs << file
end
end
和在控制器/文档\u controller.rb中
auth = request.env["omniauth.auth"]
email = auth['info']['email']
user = User.find_by_email(email) || User.create_with_omniauth(auth)
def index
session = GoogleDrive.login_with_oauth(current_user.google_tocken)
for file in session.files
@docs << file
end
end
def索引
session=GoogleDrive.login\u with\u oauth(当前用户.google\u tocken)
对于session.files中的文件
@文件