Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including ee-cordova-plugin-facebook4 with all npm packages installed. Try it out:

ee-cordova-plugin-facebook4 lists no main file and has no index.js, so it can't be directly required. If this is a mistake, please let us know. It may however contain internal files that you can require manually:

// require("ee-cordova-plugin-facebook4/[??]")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

ee-cordova-plugin-facebook4 v4.0.2

Cordova Facebook SDK 4 Plugin


Use Facebook SDK version 4 in Cordova projects


See npm package for versions -

Make sure you've registered your Facebook app with Facebook and have an APP_ID

$ cordova plugin add cordova-plugin-facebook4 --save --variable APP_ID="123456789" --variable APP_NAME="myApplication"

If you need to change your APP_ID after installation, it's recommended that you remove and then re-add the plugin as above. Note that changes to the APP_ID value in your config.xml file will not be propagated to the individual platform builds.


This is a fork of the official plugin for Facebook in Apache Cordova that implements the latest Facebook SDK. Unless noted, this is a drop-in replacement. You don't have to replace your client code.

The Facebook plugin for Apache Cordova allows you to use the same JavaScript code in your Cordova application as you use in your web application. However, unlike in the browser, the Cordova application will use the native Facebook app to perform Single Sign On for the user. If this is not possible then the sign on will degrade gracefully using the standard dialog based authentication.


  • Cordova >= 5.0.0
  • cordova-android >= 4.0 (see Android Guide for cordova-android >= 7)
  • cordova-ios >= 3.8
  • cordova-browser >= 3.6
  • Phonegap build (use phonegap-version >= cli-5.2.0, android-minSdkVersion>=15, and android-build-tool=gradle), see example here

Install Guides



facebookConnectPlugin.login(Array strings of permissions, Function success, Function failure)

Success function returns an Object like:

    status: "connected",
    authResponse: {
        session_key: true,
        accessToken: "<long string>",
        expiresIn: 5183979,
        sig: "...",
        secret: "...",
        userID: "634565435"

Failure function returns an error String.


facebookConnectPlugin.logout(Function success, Function failure)

Check permissions (iOS only)

facebookConnectPlugin.checkHasCorrectPermissions(Array strings of permissions, Function success, Function failure)

Success function returns a success string if all passed permissions are granted.

Failure function returns an error String if any passed permissions are not granted.

Get Status

facebookConnectPlugin.getLoginStatus(Function success, Function failure)

Success function returns an Object like:

    authResponse: {
        userID: "12345678912345",
        accessToken: "kgkh3g42kh4g23kh4g2kh34g2kg4k2h4gkh3g4k2h4gk23h4gk2h34gk234gk2h34AndSoOn",
        session_Key: true,
        expiresIn: "5183738",
        sig: "..."
    status: "connected"

For more information see: Facebook Documentation

Show a Dialog

facebookConnectPlugin.showDialog(Object options, Function success, Function failure)

Example options - Share Dialog:

    method: "share",
    href: "",
    caption: "Such caption, very feed.",
    description: "Much description",
    picture: '',
    hashtag: '#myHashtag',
    share_feedWeb: true, // iOS only


The default dialog mode is FBSDKShareDialogModeAutomatic. You can share that by adding a specific dialog mode parameter. The available share dialog modes are: share_sheet, share_feedBrowser, share_native and share_feedWeb. Read more about share dialog modes

caption, description and picture were deprecated in Facebok API v2.9 and therefore not supported anymore on iOS

Game request:

    method: "apprequests",
    message: "Come on man, check out my application.",
    data: data,
    title: title,
    actionType: 'askfor',
    filters: 'app_non_users'

Send Dialog:

    method: "send",
    caption: "Check this out.",
    link: "",
    description: "The site I told you about",
    picture: ""

Share dialog - Open Graph Story: (currently only fully available on Android, iOS currently does not support action_properties)

    var obj = {};

    obj['og:type'] = 'objectname';
    obj['og:title'] = 'Some title';
    obj['og:url'] = '';
    obj['og:description'] = 'Some description.';

    var ap = {};
    ap['expires_in'] = 3600;
    var options = {
        method: 'share_open_graph', // Required
        action: 'actionname', // Required
        action_properties: JSON.stringify(ap), // Optional
        object: JSON.stringify(obj) // Required

In case you want to use custom actions/objects, just prepend the app namespace to the name (E.g: obj['og:type'] = 'appnamespace:objectname', action: 'appnamespace:actionname'. The namespace of a Facebook app is found on the Settings page.

For options information see: Facebook share dialog documentation Facebook send dialog documentation

Success function returns an Object with postId as String or from and to information when doing apprequest. Failure function returns an error String.

The Graph API

facebookConnectPlugin.api(String requestPath, Array permissions, Function success, Function failure)

Allows access to the Facebook Graph API. This API allows for additional permission because, unlike login, the Graph API can accept multiple permissions.

Example permissions:

["public_profile", "user_birthday"]

Success function returns an Object.

Failure function returns an error String.

Note: "In order to make calls to the Graph API on behalf of a user, the user has to be logged into your app using Facebook login."

For more information see:


App events allow you to understand the makeup of users engaging with your app, measure the performance of your Facebook mobile app ads, and reach specific sets of your users with Facebook mobile app ads.

Activation events are automatically tracked for you in the plugin.

Events are listed on the insights page

Log an Event

logEvent(String name, Object params, Number valueToSum, Function success, Function failure)

  • name, name of the event
  • params, extra data to log with the event (is optional)
  • valueToSum, a property which is an arbitrary number that can represent any value (e.g., a price or a quantity). When reported, all of the valueToSum properties will be summed together. For example, if 10 people each purchased one item that cost $10 (and passed in valueToSum) then they would be summed to report a number of $100. (is optional)

Log a Purchase

logPurchase(Number value, String currency, Function success, Function failure)

NOTE: Both parameters are required. The currency specification is expected to be an ISO 4217 currency code

Manually log activation events

activateApp(Function success, Function failure)


In your onDeviceReady event add the following

var fbLoginSuccess = function (userData) {
  console.log("UserInfo: ", userData);

facebookConnectPlugin.login(["public_profile"], fbLoginSuccess,
  function loginError (error) {

Get Access Token

If you need the Facebook access token (for example, for validating the login on server side), do:

var fbLoginSuccess = function (userData) {
  console.log("UserInfo: ", userData);
  facebookConnectPlugin.getAccessToken(function(token) {
    console.log("Token: " + token);

facebookConnectPlugin.login(["public_profile"], fbLoginSuccess,
  function (error) {

Get Status and Post-to-wall

For a more instructive example change the above fbLoginSuccess to;

var fbLoginSuccess = function (userData) {
  console.log("UserInfo: ", userData);
  facebookConnectPlugin.getLoginStatus(function onLoginStatus (status) {
    console.log("current status: ", status);
      method: "share"
    }, function onShareSuccess (result) {
      console.log("Posted. ", result);

Getting a User's Birthday

Using the graph api this is a very simple task:

facebookConnectPlugin.api("<user-id>/?fields=id,email", ["user_birthday"],
  function onSuccess (result) {
    console.log("Result: ", result);
    /* logs:
        "id": "000000123456789",
        "email": ""
  }, function onError (error) {
    console.error("Failed: ", error);

Publish a Photo

Send a photo to a user's feed

    method: "share",
    name:'Test Post',
    message:'First photo post',
    caption: 'Testing using phonegap plugin',
    description: 'Posting photo using phonegap facebook plugin'
  }, function (response) {
  }, function (response) {
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free