【问题标题】:rails koala gem - get API url requestrails koala gem - 获取 API url 请求
【发布时间】:2016-02-26 00:13:24
【问题描述】:

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

【问题讨论】:

  • 嗨,欢迎来到堆栈溢出!你自己尝试过做什么来发现这一点? (所以我们不会重复您所做的任何努力......并且在要求我们为您做之前向我们展示您实际上已经付出了努力:))

标签: ruby-on-rails facebook-graph-api koala-gem


【解决方案1】:

改变这个

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-04-20
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    相关资源
    最近更新 更多