Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
560 views
in Technique[技术] by (71.8m points)

facebook - Graph API get photo square (100x100)

How can I get facebook photo with selection view user set (if they use large image). If I use type = "large" or "normal" or "small" in path graph then I get image but It's not square and It's not selection view of user set. So, how can I get photo with square type and it's view of user set

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can get a square picture of higher dimensions than the normal one for type=square (which will be only 50x50 pixels in size) by requesting a picture with widthand height parameters set.

See https://developers.facebook.com/docs/reference/api/user/, “picture” connection, quote:

“Additionally, you can specify width and height URL parameters to request a picture of a specific size. This will return an available profile picture closest to the requested size and requested aspect ratio. […] if width=height, we will always return a square picture.”

Example:

https://graph.facebook.com/4/picture?type=square – Mr Zuckerberg’s “normal” square profile pic, size 50x50

https://graph.facebook.com/4/picture?width=100&height=100 – 100x100 pixels, perfect match for requested size

https://graph.facebook.com/4/picture?width=150&height=150 – asking for 150x150, getting 156x156 instead.

If you can live with maybe sometimes getting images that might be a little bigger (or smaller) then the requested size, you should be fine.

Otherwise it’ll take some testing to try and figure out if there are certain square image sizes that Facebook will always have “in stock” and deliver exact matches for, or if it might differ for every user depending on the picture they uploaded.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...