Skip to main content

Login via Facebook

Prerequisite

You can get Facebook APP Id from Create an App

You can get Facebook Client Token from Client Token

Add dependencies

Add the following code in build.gradle on the app-level, and replace $msdk_version with the actual MSDK version.

    dependencies {
implementation "com.garena.sdk.android:login-facebook:$msdk_version"
}

Configuration

Configure AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

...

<!-- Facebook SDK declares this permission(optional permission), but this will block uploading to Google Play if you don't turn on advertising ID on Google Play Console
so you can use tools:node="remove" here to remove this permission -->
<uses-permission
android:name="com.google.android.gms.permission.AD_ID"
tools:node="remove" />

<application ...>

<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="[facebook_app_id]" />

<meta-data
android:name="com.facebook.sdk.ClientToken"
android:value="[facebook_client_token]" />

<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="[facebook_protocol_scheme]" />
</intent-filter>
</activity>
....
</application>

</manifest>

Usage

AccountManager accountManager = new AccountManager(activity);
accountManager.login(PlatformType.FACEBOOK, onLoginListener);

Override permissions

By default, Facebook permissions are needed: public_profile, email, user_friends

If you don't need any permission, you can override the default permissions

accountManager.login(new FacebookLoginParams(
Arrays.asList(FacebookPermission.EMAIL, FacebookPermission.PROFILE)), onLoginListener);

Get the current Facebook access token

Gets the current Facebook access token if the current user is logged in with Facebook account.

accountManager.getPlatformAccessToken(PlatformType.FACEBOOK);

Override Facebook graph API version

Facebook regularly updates and deprecates old versions of the Graph API. Upgrading the Facebook Graph API version is possible by utilizing this API without upgrading Garena MSDK.

// build the configurations
MSDKConfigs configs = new MSDKConfigs.Builder()
.setFacebookGraphApiVersion(version)
.build();
MSDK.setConfig(configs);