2016年4月24日 星期日

Published 凌晨3:25 by with 0 comment

Rails 抓取 Facebook 大頭照解析度 - 我在ALPHACamp 63天


大頭照預設大小有四種

http://graph.facebook.com/id/picture?type=small
http://graph.facebook.com/id/picture?type=square
http://graph.facebook.com/id/picture?type=large
http://graph.facebook.com/id/picture?type=normal

預設都是抓取 square, 但是不論放在手機或是網頁上~ 根本就是8bit時代的產物

所以在抓取檔案時要指定large (200x200)



手機API部分 :

app/model/user.rb,在picture加上 .type(large)

res = RestClient.get "https://graph.facebook.com/v2.4/me",  { :params => { :fields => "email,name,gender,picture.type(large)", :access_token => access_token } }
OmniAuth 部分:

config/initializers/devise.rb 之中 加上 :image_size => 'large'

config.omniauth :facebook, fb_config["facebook"]["app_id"], fb_config["facebook"]["secret"], :scope => 'public_profile,email', :info_fields => 'name,gender,email', :image_size => 'large'
對! 這樣就結束了...
      edit

0 意見:

張貼留言