Naughty Programmer's Madness
Wondering what’s next for npm?Check out our public roadmap! »


0.2.2 • Public • Published


Facebook Plugin for Cordova 5.0+


  • Cordova >= 5.0.0
  • iOS and Android
  • Login, Graph Requests, App Events

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.


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.


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

  • permissions (optional) - an array of Facebook permissions you are asking for from the user. "public_profile" is always requested. See Facebook's Docs for more information.

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

  • result.error - 1 if there was an error, 0 otherwise.
  • result.success - 1 if the user accepted the login request, 0 otherwise.
  • result.cancelled - 1 if the user cancelled the login request, 0 otherwise.
  • result.errorCode (if error is 1) - Facebook's error code for what went wrong. 0 is a network failure, 304 is a login mismatch (call logout before trying again). See Facebook List of Error Codes.
  • result.errorLocalized (if error is 1) - Facebook's localized description of what went wrong, in the current locale.
  • result.granted (if success is 1) - An array of the permissions the user approved.
  • result.declined (if success is 1) - An array of the permissions the user declined.
  • result.accessToken (if available) - The Facebook Access Token for the User.
  • result.userID (if available) - The Facebook User ID for the User.

Example usage:

   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);


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:

   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:


npm i cordova-plugin-facebook

DownloadsWeekly Downloads






Last publish


  • avatar