Thursday, March 16, 2017

get high quality facebook profile picture with cordova plugin

Leave a Comment

I'm developing ionic 2 app. I'm trying to get high quality image and then resize it to avatar photo.

My code:

 _FBUserProfile() {  return new Promise((resolve, reject) => {   Facebook.api('me?fields=id,name,email,first_name,last_name,picture.width(600).height(600).as(picture_small),picture.width(360).height(360).as(picture_large)', [])     .then((profileData) => {       console.log(JSON.stringify(profileData));       return resolve(profileData);     }, (err) => {       console.log(JSON.stringify(err));       return reject(err);     }); }); 

}

But, the photo isn't good quality, since I guess I did something wrong with the resize in this line:

picture.width(600).height(600).as(picture_small),picture.width(360).height(360).as(picture_large)', []) 

How can I get good quality of the photo?

2 Answers

Answers 1

If you want to get the public profile picture of the user and you know the user id from the api call then use this url for picture

profileData.picture="https://graph.facebook.com/"+profileData.id+"/picture?width=1024&height=1024"; 

Answers 2

You've got a couple of solutions, like using type large

id,name,email,first_name,last_name,picture.type(large) 

As explained here: https://developers.facebook.com/docs/graph-api/reference/user/picture/

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment