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

前端 未结 2 739
长发绾君心
长发绾君心 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: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

提交回复
热议问题