bisrael / cordova-plugin-facebook

Cordova Plugin for iOS and Android Facebook SDK
MIT License
25 stars 21 forks source link

CordovaFacebook

Facebook Plugin for Cordova 5.0+

Supports:

Get the Plugin:

$> cordova plugin add cordova-plugin-facebook --variable FACEBOOK_DISPLAY_NAME=<Your App Name> --variable FACEBOOK_APP_ID=<Your App ID> [--save]

Using the Plugin:

CordovaFacebook defines a single variable on window: window.CordovaFacebook.

Callbacks:

All CordovaFacebook methods accept exactly one argument: options, of type Object.

Passing in a function as options.onSuccess or options.onFailure will allow you to listen to the result of that method.

Both onSuccess and onFailure callbacks will generally be passed one argument (whose type may vary) as the result.

CordovaFacebook.login

The CordovaFacebook.login method accepts a permissions field in addition to the standard callbacks.

Both onSuccess and onFailure receive a single result object, with the following properties:

Example usage:

CordovaFacebook.login({
   permissions: ['email', 'user_likes'],
   onSuccess: function(result) {
      if(result.declined.length > 0) {
         alert("The User declined something!");
      }
      /* ... */
   },
   onFailure: function(result) {
      if(result.cancelled) {
         alert("The user doesn't like my app");
      } else if(result.error) {
         alert("There was an error:" + result.errorLocalized);
      }
   }
});

CordovaFacebook.logout

The CordovaFacebook.logout method does not have any additional options other than the standard callbacks.

Additionally, the logout method will always succeed, and never fail. (Meaning onFailure will never be called).

The onSuccess callback is not passed any arguments.

Example usage:

CordovaFacebook.logout({
   onSuccess: function() {
      alert("The user is now logged out");
   }
});

// Unless you need to wait for the native sdk to do its thing,
// you dont even really need to use a callback:
CordovaFacebook.logout();