Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 911
Huy Tran Avatar asked Aug 10 '12 11:08

Huy Tran


4 Answers

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.

like image 182
CBroe Avatar answered Nov 02 '22 00:11

CBroe


[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{ @"fields" : @"id,name,picture.width(100).height(100)"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error) {
             }

instead of 100 you can put 200 ,300 encrypt the response and get it with key

like image 41
objectiveCoder Avatar answered Nov 02 '22 00:11

objectiveCoder


Try using the type square. As follows:

http://graph.facebook.com/[user_id]/picture?type=square

The square size is limited to 50x50. If you want a large size, you will have to enlarge the square version or crop the large version.

If you don't mind retrieving and cropping an image yourself, follow my tutorial here for code to do exactly that. It will let you generate square images larger than 50px.

like image 3
Niraj Shah Avatar answered Nov 02 '22 02:11

Niraj Shah


This worked for me. Check the following query, NSString * graphPath = [NSString stringWithFormat:@"%@?fields=photos.fields(id,link,source)", albumID];

like image 2
Rahul Bansal Avatar answered Nov 02 '22 01:11

Rahul Bansal