2013-10-14 66 views
0

我已經嘗試了一切,不能解決這個從Facebook的omniauth寶石NoAuthorizationCodeError錯誤。NoAuthorizationCodeError for facebook omniauth

我已經基本上覆制和粘貼railscasts ep360。我嘗試刪除咖啡腳本,我已經更改爲寶石1.4.0,我試過不同版本的軌道。

任何幫助,將不勝感激。

at=info method=GET path=/auth/facebook/callback host=enigmatic-sands-2189.herokuapp.com fwd="105.228.66.17" dyno=web.1 connect=2ms service=27ms status=500 bytes=643 
2013-10-14T19:20:29.091206+00:00 heroku[router]: at=info method=GET path=/auth/facebook/callback host=enigmatic-sands-2189.herokuapp.com fwd="105.228.66.17" dyno=web.1 connect=14ms service=27ms status=500 bytes=643 
2013-10-14T19:20:29.071596+00:00 app[web.1]: Started GET "/auth/facebook/callback" for 105.228.66.17 at 2013-10-14 19:20:29 +0000 
2013-10-14T19:20:29.075493+00:00 app[web.1]: (facebook) Callback phase initiated. 
2013-10-14T19:20:29.084256+00:00 app[web.1]: 
2013-10-14T19:20:29.084256+00:00 app[web.1]: OmniAuth::Strategies::Facebook::NoAuthorizationCodeError (must pass either a `code` parameter or a signed request (via `signed_request` parameter or a `fbsr_XXX` cookie)): 

會話控制器

class SessionsController < ApplicationController 
    def create 
    user = User.from_omniauth(env["omniauth.auth"]) 
    session[:user_id] = user.id 
    redirect_to root_url 
    end 

    def destroy 
    session[:user_id] = nil 
    redirect_to root_url 
    end 
end 

路線

root to: 'static_pages#home' 

    match 'auth/:provider/callback', to: 'sessions#create' 
    match 'auth/failure', to: redirect('/') 
    match 'signout', to: 'sessions#destroy', as: 'signout' 

寶石文件

ruby '1.9.3' 

gem 'rails', '3.2.12' 

gem "omniauth", "~> 1.1.1" 
gem "omniauth-facebook", "1.4.0" 

用戶模型

def self.from_omniauth(auth) 其中(auth.slice(:provider,:uid))。first_or_initialize.tap do | user | user.provider = auth.provider user.uid = auth.uid user.name = auth.info.name user.oauth_token = auth.credentials.token user.oauth_expires_at = Time.at(auth.credentials.expires_at ) user.save! 結束 結束

初始化/ omniauth.rb

OmniAuth.config.logger = Rails.logger 

Rails.application.config.middleware.use OmniAuth::Builder do 
    provider :facebook, '51xxxxxxxxx42200', '0e3b1xxxxxxxxxxxxxxxxx4ff87' 
end 
+1

在facebook開發人員網站的Facebook應用程序中,您的網站網址是否被列爲您網站的基本網址?即'http:// yoursite.com'? – trh

+0

謝謝。我正嘗試使用默認的herokuapp.com url enigmatic-sands-2xx9.herokuapp.com作爲應用程序域。我把它改成了localhost,它工作正常。如果我使用自定義域,它也可以工作。如果應用程序託管在http://enigmatic-sands-2xx9.herokuapp.com,因爲它不僅僅是enigmatic-sands-2xx9.herokuapp.com – grabury

回答