【问题标题】:Get large images from Page Feed? using Koala Gem & Rails 3.2从 Page Feed 获取大图像?使用 Koala Gem & Rails 3.2
【发布时间】:2014-02-26 03:45:48
【问题描述】:

有人知道如何从 Page Feed 中提取不同尺寸的图片吗?

我尝试使用适合朋友和头像的类型哈希。

@page-feed = @graph.get_connections("somepage", "feed", {"type" => "large"})

但由于某种原因,我总是为所有帖子获得相同的图片尺寸。

谢谢!

【问题讨论】:

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


    【解决方案1】:

    在此处阅读代码:https://github.com/arsduo/koala/blob/81e66f459df840d9d5e122c0d498e2fb9d146655/lib/koala/api/graph_api.rb(第 178 行,def get_picture)您可以看到该方法接受选项哈希:
    宝石来源:

    # 获取一张照片。 # (Facebook 将照片的 src 作为响应头返回;这个方法可以正确地解析它, # 不像使用 get_connections("photo").) # # Facebook 的@param 选项选项(参见#get_object)。 # 要获得不同尺寸的照片,请传递 :type => size (small, normal, large, square)。 # @param 块(参见 Koala::Facebook::API#api) # # @note 删除照片或视频,使用 delete_object(id) # # @return 图片的 URL def get_picture(object, args = {}, options = {}, &block) # 获取图片对象,返回 URL(Facebook 将其作为标头发送) resolve_result = graph_call("#{object}/picture", args, "get", options.merge(:http_component => :headers)) 做 |result| 结果 ?结果[“位置”]:无 结尾 堵塞 ? block.call(resolved_result):resolved_result 结尾

    所以你可以把它叫做.get_picture(id, type: :large)。像这样:

    graph = Koala::Facebook::API.new(token)
    profile = graph.get_object('me')
    graph.get_picture(profile['id'], type: :large)
    

    【讨论】:

      【解决方案2】:

      以防万一其他人遇到这种情况,这是我为了检索大图像而必须做的。请注意,我只抓取提要中的第一个帖子。

      在我的控制器中:

      @fb_post = @facebook.get_connections(page_id, 'posts').first
      @photo = @facebook.get_connections(@fb_post['id'], 'attachments').first
      

      然后,为了在 img 标签内的视图中获取正确的链接,我使用了:

      @photo["media"]["image"]["src"]
      

      【讨论】:

        【解决方案3】:

        对于仍在为此苦苦挣扎的人,我可以使用 Koala 对象中的“full_picture”字段来检索图像的全分辨率 URL:

        fields = ['id','picture','full_picture']
        graphObj = Koala::Facebook::API.new(accessToken)
        hashes = graphObj.get_connection(groupId, 'feed', { limit: 10, fields: fields })
        
        hashes.each do |hash|
            mash = Hashie::Mash.new(hash)
            fullPicture = mash.full_picture
        end
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-08-19
          • 2013-02-14
          • 2012-02-15
          相关资源
          最近更新 更多