Reputation: 33
I'm using mongoid, rails 3.2.10 and omniauth on devise.. and trying to set up custom image_size of facebook profile image url
config.omniauth :facebook , API_KEYS['facebook']['api_key'], API_KEYS['facebook']['api_secret'], :image_size => {:width => 100, :height => 100}
I configured as above..
but result is as below..
http://graph.facebook.com/636937446/picture?type=#<OmniAuth::Strategy::Options height=100 width=100>
so i checked out the facebook-omniauth Strategy.rb file. please tell what should i do..
def image_url uid, options
uri_class = options[:secure_image_url] ? URI::HTTPS : URI::HTTP
url = uri_class.build({:host => 'graph.facebook.com', :path => "/#{uid}/picture"})
query = if options[:image_size].is_a?(String)
{ :type => options[:image_size] }
elsif options[:image_size].is_a?(Hash)
options[:image_size]
end
url.query = Rack::Utils.build_query(query) if query
url.to_s
end
Upvotes: 2
Views: 534
Reputation: 2457
Hi I had the same problem. I actually edited my strategy.rb
file, added my custom function and it worked perfect.
On line 39: change it to 'image' => image_url(uid,options),
Next edit the image_url method to something like this
def image_url uid, options
query = if options[:image_size].is_a?(String)
{ :type => options[:image_size] }
elsif options[:image_size].is_a?(Hash)
options[:image_size]
end
url = build_url("https://graph.facebook.com/","#{uid}/picture",query) if query
url.to_s
end
Here I call another method called "build url"
. So just after the image_url method define the "build url"
def build_url(domain,path,params)
return domain + "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')) if not params.nil?
end
Save the file and thats it!! Hope it works for you!!!
Upvotes: 1