0

UPDATE: The original question was about how to get a square thumbnail, which apparently is not possible. I have changed the question to be how do I get a custom sized thumbnail. The aspect ratio can be left as-is.

I can piece together a solution from Using facebook graph api how to get news feed with large picture size if the feed type is photo? but I am hoping for something better.

I can get a list of image sizes using

https://graph.facebook.com/v2.0/{object_id}?access_token={token}

and then I could rummage through that list to find one that is large enough but not too large and make a second request for that image.

Or, following the answers in Facebook Graph API : get larger pictures in one request, I could get a full size image returned directly in the post feed request with

https://graph.facebook.com/v2.2/{object_id}/posts?fields=full_picture

But I don't need a full size image. Is there not a way to do something like in the second example but for arbitrary image dimensions, or at least for one of the presets like you get from the first example?


Original question:

I use the Javascript below to dump a custom styled facebook feed onto a website. It shows the date and the posted text and if there is an image it grabs that as well. It looks like Facebook defaults the image to 130px wide and maintains the aspect ratio of the original image. But Facebook has a way of generating square versions of images right?

I see /s130x130/in the image URL but unfortunately changing that results in nothing being returned, because it looks like there are some random IDs in the query string that only FB knows about. I saw an example of different sized square thumbnails somewhere, but those random IDs changed for each size. So is there a way to retrieve the square versions of my images within my Javascript or if not, is there any way at all to do it?

$(function() {
    $.getJSON("https://graph.facebook.com/v2.2/1551867661729482/feed?access_token=XXXXXXXX", function(data) {

        var maxPosts = 3

        $.each(data.data, function(x) {

            if (maxPosts > 0) {

                if (data.data[x].from.name == "D'Arts") {

                    var message = data.data[x].message || //normal post
                    data.data[x].story.replace(/^You /, '').capitalizeFirstLetter() || //other updates without user text
                    "";
                    var pic = data.data[x].picture;
             pic = pic ? '<img class="fb-thumb" src="' + pic + '"></img>' : '';
                    var date = new Date( data.data[x].created_time ).toString().replace(/.* (\w\w\w \d\d) .*/,"$1");
                    var link = data.data[x].link;


                    $('#Facebook .feed-goes-here').append('<a href='+(link||'""')+' class="fb-post clearfix"><h3>'+date+'</h3>' + pic + '<p>' + message + '</p></a>');

                    maxPosts--;

                }



            } else {
                return false
            }



        })

    })
})
Community
  • 1
  • 1
Moss
  • 3,695
  • 6
  • 40
  • 60
  • 1
    No, AFAIK it is not possible to request post pictures in a square format. Simplest way to achieve this would perhaps be to use them as background image for a square container element, and `background-size:cover`. (Or `object-fit` if you need them to be `img` elements – but that does not have great browser support as of now.) – CBroe Jan 08 '16 at 11:05
  • Hmm, so the square thing is just for profile pictures? Yeah I guess background image of a square element works. Only slightly bandwidth inefficient. – Moss Jan 08 '16 at 18:32

0 Answers0