Wizcorp / phonegap-facebook-plugin

The official plugin for Facebook in Apache Cordova/PhoneGap
Other
1.91k stars 2k forks source link

how to retrieve a larger version of the standard facebook profile picture that comes back from an api call. #1316

Open sarahmonks opened 8 years ago

sarahmonks commented 8 years ago

Hi,

I was working with the normal web facebook javascript sdk and was able to retrieve a large version of the user's profile pic with the following api call: FB.api("/me/picture?type=large", ["public_profile"], function(response_pic) { fb_picture_url = response_pic.data.url; });

Now imtrying to retrieve the same within my phonegap build however its not returning anything from the api call. is there another more suitable way to do this for phonegap environment? facebookConnectPlugin.api("/me/picture?type=large", ["public_profile"], function(response_pic) { fb_picture_url = response_pic.data.url; });

thanks

c4rl0s00 commented 7 years ago

Maybe a little bit later, but, this is how I did it: First:

api("me/?fields=first_name,last_name,picture", ["public_profile"], function(success){}, function(failure){})

to get user session values (nothing else to do here)

Then: use api to get profile picture in a better quality with:

facebookConnectPlugin.api(
    "me/picture?width=300&height=300&redirect=false",
    ["public_profile"],
    function (res) {
        var myProfileImage = res.data.url;
    },
    function (res) {}
);

I used this function on the first success callback, so, my final code is:

facebookConnectPlugin.api(
    "me/?fields=first_name,last_name,picture",
    ["public_profile"],
    function (response) {
        var imageBadQuality = response.picture.data.url;
        var name= response.first_name + ' ' + response.last_name;
        try {
            facebookConnectPlugin.api(
                "me/picture?width=300&height=300&redirect=false",
                ["public_profile"],
                function (responsive) {
                    var imageGoodQuality = res.data.url;
                },
                function (responsive) {}
                );
            } catch (err) {}
        }catch(err){}
);

Hope this work. See ya