有谁知道如何从Page Feed中提取不同尺寸的图片?
我试图使用适合朋友和个人资料图片的Type哈希。
@ page-feed = @ graph.get_connections(“somepage”,“feed”,{“type”=>“large”})
但出于某种原因,我总是为所有帖子获得相同的图片大小。
谢谢!
答案 0 :(得分:4)
在此处阅读代码:https://github.com/arsduo/koala/blob/81e66f459df840d9d5e122c0d498e2fb9d146655/lib/koala/api/graph_api.rb(第178行,def get_picture
)您可以看到该方法接受选项哈希:
宝石来源:
# Fetches a photo. # (Facebook returns the src of the photo as a response header; this method parses that properly, # unlike using get_connections("photo").) # # @param options options for Facebook (see #get_object). # To get a different size photo, pass :type => size (small, normal, large, square). # @param block (see Koala::Facebook::API#api) # # @note to delete photos or videos, use delete_object(id) # # @return the URL to the image def get_picture(object, args = {}, options = {}, &block) # Gets a picture object, returning the URL (which Facebook sends as a header) resolved_result = graph_call("#{object}/picture", args, "get", options.merge(:http_component => :headers)) do |result| result ? result["Location"] : nil end block ? block.call(resolved_result) : resolved_result end
所以你可以像.get_picture(id, type: :large)
一样调用它。像这样:
graph = Koala::Facebook::API.new(token)
profile = graph.get_object('me')
graph.get_picture(profile['id'], type: :large)
答案 1 :(得分:3)
以防万一其他人遇到这个问题,这是我为了检索大图片而必须做的事情。请注意,我只是抓住了Feed中的第一篇文章。
在我的控制器中:
@fb_post = @facebook.get_connections(page_id, 'posts').first
@photo = @facebook.get_connections(@fb_post['id'], 'attachments').first
然后,为了获取img标签内部视图中的正确链接,我使用了:
@photo["media"]["image"]["src"]
答案 2 :(得分:3)
对于仍在努力解决这个问题的人,我能够使用' full_picture'我的Koala对象中的字段,用于检索图像的全分辨率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