0

我正在使用 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

但我想保存考拉正在使用的 url(我更喜欢用户调用 url,而不是我)。我假设 gem 调用: https ://graph.facebook.com/facebook_id/picture

但我不希望它被硬编码。有没有办法从 gem 中提取 url?谢谢

4

1 回答 1

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
于 2016-02-25T16:13:24.110 回答