Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Account Kit in Ionic/Cordova app

I try to connect Facbook Account Kit in Ionic/cordova App, main problem i faced that in facebook account kit set client/server side domain name but in ionic/cordova app the webview serve from file system("file:///android_asset/www/index.html#/app/request"). So how to do this in Ionic app.

like image 458
Zahidur Rahman Avatar asked Jul 28 '16 10:07

Zahidur Rahman


People also ask

How do I connect my Facebook app with Cordova?

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: Click 'Add Platform'.

How do I add a native platform to my Facebook app?

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: Click 'Add Platform'. At this point you'll need to open your project's config.xml file, found in the root directory of your project.

How can account kit help my app grow?

Whether your app is in its conceptual stages or already established, Account Kit can help you grow by giving people more ways to log in. Saavn, a music streaming app, saw over half a million registered phone number users and a 33% increase in daily new registrants within the first two months after integrating Account Kit phone number login.

How do I connect to Facebook on iOS and Android?

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.


1 Answers

You can use plugin instead of webview https://github.com/gurisko/cordova-plugin-accountkit

Steps:

  1. Create a Facebook application from https://developers.facebook.com
  2. Enable Accountkit; Copy required credentials
  3. Add AccountKit plugin

cordova plugin add cordova-plugin-accountkit --save --variable APP_ID="123456789" --variable APP_NAME="myApplication" --variable CLIENT_TOKEN="abcdefghijklmnopqrstuvwxyz"

AccountKitPlugin.loginWithPhoneNumber({
    useAccessToken: true,
    defaultCountryCode: "US",
  },function(res){
    console.log(res)
  },function(err){
     console.log(err)
})

Incase of Ionic with typescript just add (window) before function

(<any>window).AccountKitPlugin.loginWithPhoneNumber({
    useAccessToken: true,
    defaultCountryCode: "US",
  },function(res){
    console.log(res)
  },function(err){
     console.log(err)
})

Reference: https://codesundar.com/ionic-accountkit-integration/

like image 67
Sundaravel M Avatar answered Nov 07 '22 09:11

Sundaravel M