Does anyone know how to pull different size images from the Page Feed?

I was trying to use the Type hash that works great for friends and profile pictures.

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

but for some reason I'm always getting the same picture size for all posts.

Thanks !

有帮助吗?

解决方案 2

Just in case anyone else comes across this, this is what I had to do in order to retrieve the large images. Note that I'm only grabbing the first post in the feed.

In my controller:

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

Then, to grab the proper link in the view inside of an img tag, I used:

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

其他提示

Reading the code here: https://github.com/arsduo/koala/blob/81e66f459df840d9d5e122c0d498e2fb9d146655/lib/koala/api/graph_api.rb (line 178, def get_picture) you can see that the method accepts options hash:
Gem source:

# 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

So you can call it like .get_picture(id, type: :large). Like this:

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

For anyone still struggling with this, I was able to use the 'full_picture' field in my Koala object to retrieve a full-resolution URLs of the images:

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top