3

I'm working with omniauth-facebook and devise gem. I want to get some information of an user. But I don't know why I can't get birthday.

Config in devise.rb:

config.omniauth :facebook, ENV["APP_ID"], ENV["APP_SECRET"], scope: "email,public_profile,user_birthday", info_fields: "email,name,gender,birthday"

Controller:

class User::OmniauthCallbacksController < Devise::OmniauthCallbacksController
 def facebook
   user_info = request.env["omniauth.auth"]
   @user = User.find_by_uid user_info.uid
   if @user
     sign_in @user, event: :authentication
     # set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format?
     redirect_to user_root_path
   else
     redirect_to new_user_user_path(uid: user_info.uid,
     email: user_info.info.email, name: user_info.info.name)
   end
 end

 def failure
   redirect_to user_session_path
 end
end

Model:

class User < ActiveRecord::Base  
  devise :database_authenticatable, :registerable,
    :recoverable, :rememberable, :trackable, :validatable
  devise :omniauthable, omniauth_providers: [:facebook]

  belongs_to :email_language, class_name: M::SystemLanguage.name,
    foreign_key: :email_language_id

  validates :email, presence: true, length: {maximum: 255}
  validates :uid, uniqueness: true

  def active_for_authentication?
    super && !withdrawn_at
  end

  class << self
    def available include_withdrawn
      include_withdrawn ? all : where("withdrawn_at IS NULL")
    end
  end
end

I get value from user_info.extra.raw_info.birthday but it return nil.

huyhoang-vn
  • 335
  • 1
  • 3
  • 13

0 Answers0