jeduan / cordova-plugin-facebook4

Use the latest Facebook SDK in your Cordova and Ionic projects
Other
767 stars 511 forks source link

Facebook api calling a users picture (no redirect) #891

Closed philippogol closed 3 years ago

philippogol commented 3 years ago

How to correctly call the user picture with the last Facebook api changes? I tried following code and I just get the name and id but not the picture:

facebookConnectPlugin.api("me/picture?height=200", [], function (response) { alert(JSON.stringify(response)); });

I also tried this call but cant handle the URL, it seems the auto redirect breaks the returned URL

facebookConnectPlugin.api("me/?fields=picture.width(500).height(500).redirect(0)", [], function (response) { alert(JSON.stringify(response.picture.data)); });

The Facebook Graph API tool works but also the returned URL has the same redirect issue

noahcooper commented 3 years ago

This plugin is deprecated. See cordova-plugin-facebook-connect at https://www.npmjs.com/package/cordova-plugin-facebook-connect.

I tested and confirmed that the following request successfully returns data about the user's picture:

facebookConnectPlugin.api('me/picture?height=200&&fields=&redirect=false&access_token=' + myAccessToken, [], function(response) {
  console.log(response);
});

Two key things to note:

1) Since v2.4 of the Facebook SDK, you must explicitly pass the fields parameter. You can set it to an empty value as seen here, or if you only want the picture URL for example, you can use something like fields=url. 2) You must include the redirect=false query parameter to receive back JSON data about the picture.

(Note that the example above assumes you've already received "public_profile" permissions from the user.)