我已經安裝了omniauth 1.0。我也有oauth-0.4.5,oauth2-0.5.1,omniauth-facebook-1.0.0,omniauth-twitter-0.0.6。omniauth OAuthException&OAuth ::未授權
omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer unless Rails.env.production?
provider :facebook, ENV['167257285348131'], ENV['c8c722f697scb2afcf1600286c6212a9'], :scope => 'email,offline_access,read_stream', :display => 'popup'
provider :twitter, ENV['fma2L22ObJCW52QrL7uew'], ENV['4aZfhCAOdiS7ap8pHJ7I1OZslFwVWWLiAMVpYUI']
end
session_controller.rb
class SessionsController < ApplicationController
require 'omniauth-facebook'
require 'omniauth-twitter'
require 'omniauth'
def create
@user = User.find_or_create_from_auth_hash(auth_hash)
self.current_user = @user
redirect_to '/'
end
def auth_hash
request.env['omniauth.auth']
end
end
另外我想補充 'omniauth' 'omniauth Facebook的' 「omniauth,Twitter的寶石的Gemfile
有兩個問題:
- 當我去http://localhost:3000/auth/facebook我得到「 { 」error「:{ 」message「:」Missing client_id parameter。「, 」type「:」OAuthException「 } }
和連桿graph.facebook.com/oauth/authorize?response_type=code & CLIENT_ID = & REDIRECT_URI = HTTP%3A%2F%2Flocalhost%3A3000%2Fauth%2Ffacebook%2Fcallback &解析=查詢& scope = email%2Coffline_access%2Cread_stream & display = popup 而且沒有client_id !!!
- 當我去http://localhost:3000/auth/twitter我得到的OAuth ::未經授權
401未授權
任何想法?
你解決facebook的錯誤更新你的配置
?如果是這樣,我可以解決這個問題嗎?我收到相同的錯誤消息。它可以解決,如果我手動添加client_id查詢字符串參數 – Vina
@Vina ENV []打破它。嘗試僅使用「」。例如:提供者:Facebook,'167257285348131','c8c722f697scb2afcf1600286c6212a9' –
謝謝,它的工作!看來我還需要重啓webrick。 :D – Vina