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
- Android
- iOS
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
- Android
- iOS
- Unity
- Unreal
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>
Configure Info.plist
FacebookDisplayName - The value of this key must be an exact match to the value of the Display Name field under Settings in the Facebook devapp.
fbapi - This can enable your app to perform an app switch to Facebook app for login authentication.
fb{APP-ID} - This is to enable Facebook app to perform an app switch back to your App after login authentication.
<key>FacebookAppID</key>
<string>123456789</string>
<key>FacebookDisplayName</key>
<string>facebook display name</string>
<key>FacebookClientToken</key>
<string>client_token</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb123456789</string>
</array>
</dict>
</array>
You may directly set the automatic collection of App Events to "true" or "false" by adding FacebookAutoLogAppEventsEnabled as a key in Info.plist. It's "true" by default.
Configure facebook_app_id, facebook_client_token, and facebook_protocol_scheme in Window -> GMSDK Settings
Configure FaceBookAppID,FacebookClientToken,FacebookContentProviderAuthorities,FacebookDisplayName,FacebookUrlSchemeSuffix in Edit -> Project Settings -> Plugins -> Garena MSDK
Usage
- Android
- iOS
- Unity
- Unreal
AccountManager accountManager = new AccountManager(activity);
accountManager.login(PlatformType.FACEBOOK, onLoginListener);
[MSDKLoginManager loginWithPlatform:MSDKePlatformFb completion:^(MSDKLoginRet *loginRet) {
// handle login result
}];
If user disables App Tracking for your app, login with Facebook will be using Facebook Limited Login. Login using Limited Login will not redirect users to the App and use in-game browser even if FB App is installed. Additionally, sessions created using Limited Login will not provide FB Access Token and might restrict some data usage
GMSDKHandler.LoginClient.Login(AccountPlatform.Facebook, OnLoginCallback);
UMsdkLogin::Login(Facebook);
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
- Android
- iOS
- Unity
- Unreal
accountManager.login(new FacebookLoginParams(
Arrays.asList(FacebookPermission.EMAIL, FacebookPermission.PROFILE)), onLoginListener);
var facebookLoginParams = new FacebookLoginParams
{
androidFacebookPermissions = new List<AndroidFacebookPermission> { AndroidFacebookPermission.Email },
};
GMSDKHandler.LoginClient.Login(facebookLoginParams, OnLoginCallback);
FLoginParams Params;
Params.platform = Facebook;
Params.androidFacebookPermissions = { static_cast<int32>(AndroidFacebookPermissionEmail) };
UMsdkLogin::LoginWithParams(Params);
Get the current Facebook access token
Gets the current Facebook access token if the current user is logged in with Facebook account.
- Android
- iOS
- Unity
- Unreal
accountManager.getPlatformAccessToken(PlatformType.FACEBOOK);
// Returns the token as a string. If the token does not exist, it returns an empty string.
NSString *tokenString = [MSDKLoginManager.shared getFacebookAccessToken];
NSLog(@"Facebook Access Token: %@", tokenString);
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.
- Android
- iOS
- Unity
- Unreal
// build the configurations
MSDKConfigs configs = new MSDKConfigs.Builder()
.setFacebookGraphApiVersion(version)
.build();
MSDK.setConfig(configs);
[[FacebookSDKService shared] changeFacebookGraphAPIVersion:version];