How to get a specific size album photo

2019-05-21 19:04发布

问题:

I can retrieve the list of photos of an album just fine and yes there are different sizes in the photos array returned, my question however is: is there any way to specify the dimensions of the image you want to return.

Array returned from /photos call

[id] => COVER PHOTO ID
[from] => Array(
    [name] => FB_USER NAME
    [id] => FB_USER ID
)
[name] => PHOTO NAME
[picture] => https://photos-b.xx.fbcdn.net/hphotos-ash4/xxxxxxxxxxxx_s.jpg
[source] => https://sphotos-b.xx.fbcdn.net/hphotos-ash4/s720x720/xxxxxxxxxxxx_n.jpg
[height] => 540
[width] => 720
[images] => Array(
    [0] => Array(
        [height] => 1224
        [width] => 1632
        [source] => https://sphotos-b.xx.fbcdn.net/hphotos-ash4/xxxxxxxxxxxx_o.jpg
    )

    [1] => Array(
        [height] => 720
        [width] => 960
        [source] => https://sphotos-b.xx.fbcdn.net/hphotos-ash4/xxxxxxxxxxxx_n.jpg
    )

    [2] => Array(
        [height] => 540
        [width] => 720
        [source] => https://sphotos-b.xx.fbcdn.net/hphotos-ash4/s720x720/xxxxxxxxxxxx_n.jpg
    )

    [3] => Array(
        [height] => 450
        [width] => 600
        [source] => https://sphotos-b.xx.fbcdn.net/hphotos-ash4/s600x600/xxxxxxxxxxxx_n.jpg
    )
    ... other sizes
    [link] => ALBUM LINK
    [icon] => https://fbstatic-a.akamaihd.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif
    [created_time] => 2012-10-14T03:52:17+0000
    [updated_time] => 2012-10-14T03:52:17+0000
)

Is there any way to use the album's cover photo id with the graph /picture api to resize?

https://developers.facebook.com/docs/reference/api/using-pictures/

Notice how you can do ?width=xxxx&height=xxxx

回答1:

You can't.

As this doc indicates, you can only resize pictures, not photos.

  • Pictures are only a way to represent an object, like a profile, an event, a page or an album. Pictures work as simple representation, logo, description or whatever ; this is why they should fit to any kind of displaying.
  • Photos are the photos you will find in an album. These are objects themselves and doesn't need a picture to be represented. I guess the logic wants photos not to be resized, because they shouldn't be denaturalized.

So, you will have to resize these photos yourself. At least, you can choose a dimension for your photo.