首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用facebook身份验证rails访问电子邮件

使用facebook身份验证rails访问电子邮件
EN

Stack Overflow用户
提问于 2013-05-20 21:43:36
回答 1查看 104关注 0票数 0

我无法通过facebook身份验证访问用户电子邮件。我在身份验证控制器中的代码

定义facebook

代码语言:javascript
运行
复制
     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',‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxd47aae3’,{:scope =>‘email,publish_stream,offline_access’,:display => 'popup'}

在用户模型中

代码语言:javascript
运行
复制
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']                  

结束

代码里有他们的东西吗?

EN

回答 1

Stack Overflow用户

发布于 2013-05-20 21:54:50

最后,我记得,可以在omni.info.email上找到email

另外,我建议您在这里使用.表示法,而不是哈希。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16650892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档