我正在使用rails 4,使用Koala gem从Graph API检索用户图片。
我可以收到宝石来接收图片:
picture, picture_medium, picture_small = graph.batch do |batch_api|
batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_LARGE, 'height' => PIC_SIZE_LARGE}, 'return_ssl_resources' => '0')
batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_MED, 'height' => PIC_SIZE_MED}, 'return_ssl_resources' => '0')
batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_SMALL, 'height' => PIC_SIZE_SMALL}, 'return_ssl_resources' => '0')
end
但我想保存Koala正在使用的网址(我预先知道用户会调用网址,而不是我)。 我假设gem调用: https://graph.facebook.com/facebook_id/picture
但我不希望它被硬编码。 有没有办法从宝石中提取网址? 感谢
答案 0 :(得分:0)
更改此
picture, picture_medium, picture_small = graph.batch do |batch_api|
batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_LARGE, 'height' => PIC_SIZE_LARGE}, 'return_ssl_resources' => '0')
batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_MED, 'height' => PIC_SIZE_MED}, 'return_ssl_resources' => '0')
batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_SMALL, 'height' => PIC_SIZE_SMALL}, 'return_ssl_resources' => '0')
end
到这个
@graph = Koala::Facebook::API.new(oauth_access_token)
@graph.batch do |batch_api|
@large_pic = batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_LARGE, 'height' => PIC_SIZE_LARGE}, 'return_ssl_resources' => '0')
@med_pic = batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_MED, 'height' => PIC_SIZE_MED}, 'return_ssl_resources' => '0')
@small_pic = batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_SMALL, 'height' => PIC_SIZE_SMALL}, 'return_ssl_resources' => '0')
end
然后在您的视图中将照片保存到数据库
= image_tag @large_pic