0
Meine Rails App hat fb Login, wenn der Benutzer über fb Login authentifiziert wird dann bekomme ich seine E-Mail und vollen Namen, kann aber nicht sein Profil Bild bekommen.Rails App nimmt nicht Facebook Bild nach fb Login
My Application Helfer,
module ApplicationHelper
def avatar_url(user)
if user.avatar
user.avatar
else
"/images/missing.png"
end
end
Ende
Omniauth_callbacks_controller.rb ist,
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
def google_oauth2
@user = User.from_omniauth(request.env['omniauth.auth'])
if @user.persisted?
sign_in_and_redirect @user, event: :authentication
set_flash_message(:notice, :success, :kind => "Google") if is_navigational_format?
else
redirect_to root_path, flash: { error: 'Authentication failed!' }
end
Ende
Ende
meinen Benutzer Modell ist,
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable, omniauth_providers: [:google_oauth2, :facebook]
validates :fullname, presence: true, length: {maximum: 40}
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100#" }, :default_url => "/images/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.fullname = auth.info.name
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.avatar = auth.info.avatar
user.password = Devise.friendly_token[0,20]
end
end
end
ich die Genehmigung von Facebook bin immer aber nicht fb profile pic bekommen.
+0