FACEBOOK ACCOUNT KIT INTEGRATION – ANDROID

Account Kit

Account Kit lets people quickly register for and login to your app by using just their phone number or email address — no password needed. It’s reliable, easy to use and gives you a choice about how you sign up for apps.

To set up Account Kit in your Android app, if you don’t have a Facebook developer account create a Developer Account. Then Account Kit for Android requires a Facebook app ID. Follow the steps. Choose whether to allow email and SMS login, and choose security settings for your app.

Configure the SDK

Add your Facebook app ID and your Account Kit client token to the AndroidManifest.xml file. You’ll find the Account Kit client token in the Account Kit section of the App Dashboard. The application name will be used in the UI on the login screen.

Add the compile dependency with the latest version of the Account Kit SDK in the build.gradle file:

Add the following to the application tag of your AndroidManifest.xml

Make sure @style/AppLoginTheme inherits from Theme.AccountKit.

Define the value for FACEBOOK_APP_ID as the Facebook app ID shown at the top of your application dashboard, and the value for ACCOUNT_KIT_CLIENT_TOKEN using the client token found in the Account Kit tab in the App Dashboard.

The AccountKitActivity must be defined here as well, to enable it to start in the app. Set the android:themeattribute here to customize the color scheme of the UI.

If you wish to disable App Events for your Account Kit application, add the following line toAndroidManifest.xml:

Initiate a Login flow for SMS

The APP_REQUEST_CODE is your custom code to track your login flow. It can be any integer, but it needs to be set by your application.

When initializing your intent extras, be sure to specify the AccountKitActivity.

ResponseType that matches your application’s authorization setting in the Facebook developer portal dashboard: TOKEN if the Enable Client Access Token Flow switch in your app’s dashboard is ON, and CODE if it is OFF.

Initiate a Login flow for Email

The APP_REQUEST_CODE is your custom code to track your login flow. It can be any integer, but it needs to be set by your application.

When initializing your intent extras, be sure to specify the AccountKitActivity.ResponseType that matches your application’s authorization setting in the Facebook developer portal dashboard: TOKEN if the Enable Client Access Token Flow switch in your app’s dashboard is ON, and CODE if it is OFF.

With Account Kit email login, people receive an email sent to their account. When they click on the link in the email on the same device that your app is installed on, they return to your app to finish the login activity.

To return people to your app, add the AccountKitEmailRedirectActivity activity with the following intent filter to your AndroidManifest.xml file:

And the following in your strings.xml file:

// if your Facebook App ID is 1234567, you should use ak1234567

Handle the Activity’s Result

Capture the Account Kit activity’s result and extract the AccountKitLoginResult from the Intent argument to determine the status of the login attempt.

If you began the login session with AccountKitActivity.ResponseType.TOKEN, a logout option is available to remove the stored AccessToken from the device.

Access Account Information on the Device

If your began the login session with AccountKitActivity.ResponseType.TOKEN, it’s possible to access the Account Kit ID, phone number and email of the current account via a call to getCurrentAccount().

Example Application : Dither

 

magento-banner