Skip to main content

Facebook

Use the Facebook Connect plugin to obtain access to the native FB application on iOS and Android.

Requires Cordova plugin: cordova-plugin-facebook-connect. For more info, please see the Facebook Connect.

Installation​

To use the FB plugin, you first have to create a new Facebook App inside of the Facebook developer portal at https://developers.facebook.com/apps.

The Facebook Developer Portal with a highlighted 'Add a New App' button.

Retrieve the App ID and App Name.

Dashboard view of a Facebook app showing the App ID and API Version details.

Then type in the following command in your Terminal, where APP_ID and APP_NAME are the values from the Facebook Developer portal.

ionic cordova plugin add cordova-plugin-facebook-connect --variable APP_ID="123456789" --variable APP_NAME="myApplication"

After, you'll need to add the native platforms you'll be using to your app in the Facebook Developer portal under your app's Settings:

Dropdown menu in the Facebook App Settings showing options including 'Dashboard' and 'Settings'.

Click 'Add Platform'.

Facebook App Basic Settings screen with an 'Add Platform' option visible.

At this point you'll need to open your project's config.xml file, found in the root directory of your project.

Take note of the id for the next step:

<widget id="com.mycompany.testapp" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

You can also edit the id to whatever you'd like it to be.

iOS Install​

Under 'Bundle ID', add the id from your config.xml file:

Field to enter the iOS Bundle ID in the Facebook App Settings for iOS installation.

Android Install​

Under 'Google Play Package Name', add the id from your config.xml file:

Field to enter the Google Play Package Name in the Facebook App Settings for Android installation.

And that's it! You can now make calls to Facebook using the plugin.

Events​

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.

For tracking events, see logEvent and logPurchase.

github.com/cordova-plugin-facebook-connect/cordova-plugin-facebook-connect

Stuck on a Cordova issue?

Don't waste precious time on plugin issues.

If you're building a serious project, you can't afford to spend hours troubleshooting. Ionic’s experts offer premium advisory services for both community plugins and premier plugins.

Installation

$ npm install cordova-plugin-facebook-connect $ npm install @awesome-cordova-plugins/facebook $ ionic cap sync

Supported Platforms​

  • Android
  • iOS
  • Browser

Usage​

React​

Learn more about using Ionic Native components in React

Angular​

import { Facebook, FacebookLoginResponse } from '@awesome-cordova-plugins/facebook/ngx';

constructor(private fb: Facebook) { }

...

this.fb.login(['public_profile', 'user_friends', 'email'])
.then((res: FacebookLoginResponse) => console.log('Logged into Facebook!', res))
.catch(e => console.log('Error logging into Facebook', e));


this.fb.logEvent(this.fb.EVENTS.EVENT_NAME_ADDED_TO_CART);