How to get larger version of Facebook's thumbnail images?

前端 未结 2 731
长发绾君心
长发绾君心 2020-12-21 05:34

Right now the Facebook API is returning a URL like this with all post/album images 130x130 pixels in size:

https://fbcdn-sphotos-h-a.akamaihd.net/hpho

相关标签:
2条回答
  • 2020-12-21 05:50
    https://graph.facebook.com/{object_id}/picture?type={thumbnail|album|normal}
    

    Example (using a bogus object_id of 122233334444555):

    https://graph.facebook.com/122233334444555/picture?picture?type=large
    

    Make sure object_id is not just the id of an item but it's object_id (which is typically the number following the underscore in the full id).

    I got those type values from a helpful facebook response message that said:

    "message": "(#100) type must be one of the following values: thumbnail, album, normal"
    

    In place of ?type=... you could do height/width as well:

    ?width=543&height=543
    
    0 讨论(0)
  • 2020-12-21 05:56

    After a couple of hours searching and pulling my hair out, I found a solution that works for me. In my case I'm pulling posts from {page-id}/posts, but I'm pretty sure this will work for you too, seeing that I used to get larger images using the same approach as you mention.

    This is works for me:

    bigger_image="https://graph.facebook.com/" + picture_url_from_facebook.match(/_\d+/)[0].slice(1) + "/picture?type=normal";
    
    • /_\d+/ matches any substring starting with an underscore (_) followed by any digits (\d matches one digit, \d+ does the digit match over and over until it fails)
    • match(regex) returns an array with all strings it could find matching the specified regex
    • we grab the first ([0]) element, as this will be an underscore followed by the ID of the picture in Facebook's database
    • we slice the string from index 1 to the end, as the underscore is not a part of the ID
    • we then get a working link from facebook using the graph api without the need for any extra calls (you can use this in for example an img tag directly)

    You can see this working in action @ this fiddle or this page we did for a client

    Thanks to Er Adhish for leading the way to the solution @ https://stackoverflow.com/a/27075503/2908761

    0 讨论(0)
提交回复
热议问题