0

Facebook 認証でユーザーのメールにアクセスできません。認証コントローラーの私のコード

デフフェイスブック

     omni= request.env["omniauth.auth"]
authentication = Authentication.find_by_provider_and_uid(omni['provider'],omni['uid'])
    if authentication
        flash[:notice]="Logged in successfully"
        sign_in_and_redirect User.find(authentication.user_id)
    elsif current_user
        token=omni['credentials'].token
        token_secret=omni['credentials'].secret

        current_user.authentications.create!(:provider=>omni['provider'],:uid=>omni['uid'],:token=>token,:token_secret=>token_secret)
        flash[:notice]="Authentication successful."
        sign_in_and_redirect current_user
    else
        user=User.new
    #   user.email=omni['extra']['raw_info'].email
        user.apply_omniauth(omni)
        if user.save
            flash[:notice]="Logged in."
            sign_in_and_redirect User.find(user.id)
        else
            session[:omniauth]=omni.except('extra')
            redirect_to new_user_registration_path
        end 
    end
end

devise.rb

config.omniauth :facebook, 'xxxxxxxxxxxxxxx851','xxxxxxxxxxxxxxxxxxd47aae3', {:scope => 'メール,publish_stream,offline_access' ,:display => 'popup'}

ユーザーモデルで

def apply_omniauth(omni)
  authentications.build(:provider => omni['provider'],
  :uid=>omni['uid'],
  :token=>omni['credentials'].token,
  :token_secret=>omni['credentials'].secret,
  )

  x=omni["info"]["name"].split                              # split the full name into first and last name                                  
  self.first_name=x[0]
  self.last_name=x[1]
  self.profile_name=omni['info']['nickname']                  

終わり

彼らはコードに何かありますか?

4

1 に答える 1

0

最後に、私が覚えているのは、 にemailありますomni.info.email。また、ここではハッシュではなく表記法
を使用することをお勧めします。.

于 2013-05-20T13:54:49.723 に答える