Calling Facebook.api


#1

Hi, it’s me again, more basic troubles.

what is the correct sintax to use Facebook.api(), this is my code

Facebook.status is connected, but my getFacebookData doesn’t works

getFacebookData(){
	  Facebook.api("/me", "{fields: 'last_name'}", ["public_profile"]).then(
			(result) => {
				alert('OK '+ result);
			}, (error) => {
				alert('Error ' + JSON.stringify(error));
			}
		);
  }

and the result is “OK JSON error”

Please your Help.

Thanks.


#2

Below is my code and it works for me

facebookConnectPlugin.api('/'+ userId + "/?fields=id,email,name,gender", [],
        function onSuccess (result) {
          alert("Result: " + result);
          alert("Email: " + result.email);
        }, function onError (error) {
          alert("Failed: " + error);
        });

#3

Hi thanks, it works for me, but on ionic 2 the Facebook.api Returns a Promise that resolves with the result of the request, or rejects with an error.

so mi code now is…

facebookData(){
	  Facebook.api('/' + id + "/?fields=id,email,name,gender", ["public_profile"]).then(
			(result) => {
				alert('OK '+ JSON.stringify(result));
			}, (error) => {
				alert('Error ' + JSON.stringify(error));
			}
		);
  }

Thanks a lot


#4

Hi,

Thanks for your information. Anyway, my code also work in Ionic 2 project.
I just wondering whether it works for me if I apply the same way to google+.