androidfacebookgigya

Unable to use Facebook native App with Gigya Social Login in Android


I'm having a hard time integrating Facebook native with Gigya social login. I am already able to authenticate a user if they proceed through the browser.

I'm using code similar to the sample apps provided in the Gigya documentation.

I've tried replacing the API keys and application IDs on the sample app with my keys and IDs and I got the Facebook native app to work when I use the presentNativeLogin() so I've ruled out that it's my Facebook app ID.

App-Level build.gradle file

//Gigya
implementation files('src/main/java/com/example/myproj/libs/gigya-android-sdk-4.0.1.aar')

//Facebook
implementation 'com.facebook.android:facebook-android-sdk:4.41.0'

//Google Sign In
implementation 'com.google.android.gms:play-services-auth:16.0.1'

Manifest

<meta-data
    android:name="com.facebook.sdk.ApplicationId"
    android:value="MY APP ID" />

<meta-data
    android:name="apiKey"
    android:value="MY API KEY" />

<meta-data
    android:name="apiDomain"
    android:value="MY DOMAIN"/>

<meta-data
    android:name="googleClientId"
    android:value="MY CLIENT ID" />

<activity
    android:name="com.gigya.android.sdk.ui.HostActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:theme="@style/Theme.AppCompat.Translucent" />

<activity
    android:name="com.gigya.android.sdk.ui.WebLoginActivity"
    android:allowTaskReparenting="true"
    android:launchMode="singleTask"
    android:theme="@style/Theme.AppCompat.Translucent">
    <intent-filter android:label="web_login_redirect">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:host="gsapi"
            android:pathPrefix="/com.example.myproj/login_result"
            android:scheme="gigya" />
    </intent-filter>
</activity>

<activity
    android:name="com.facebook.FacebookActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    tools:replace="android:theme" />

onCreate on my Application class

public void onCreate() {
    super.onCreate();

    //Gigya Implementation
    // Allow WebViews debugging.
    WebView.setWebContentsDebuggingEnabled(true);

    // Enable Gigya logs in debug mode.
    GigyaLogger.setDebugMode(true);
    // Crucial. Call before first instantiation of the SDK.
    Gigya.setApplication(this);
    Gigya.getInstance(MyAccount.class);
}

Process Login

private val gigya: Gigya<MyAccount> = getInstance(MyAccount::class.java)

fun processGigyaLogin(loginProvider: String) {
    val providers = listOf(FACEBOOK, GOOGLE)
    gigya.socialLoginWith(providers, HashMap<String, Any>(), object : GigyaLoginCallback<MyAccount>() {
        override fun onSuccess(obj: MyAccount) {
            // Success
            Log.i("GIGYA-CDC", "Logged in using" + obj.socialProviders + " as: " + obj.profile!!.firstName + " " + obj.profile!!.lastName + ", " + obj.profile!!.email)
        }

        override fun onConflictingAccounts(response: GigyaApiResponse, resolver: ILinkAccountsResolver) {
            Log.d("GIGYA-CDC", "onConflictingAccounts")
            resolver.linkToSocial(resolver.conflictingAccounts.loginProviders[0])
        }

        override fun onPendingRegistration(response: GigyaApiResponse, resolver: IPendingRegistrationResolver) {
            Log.d("GIGYA-CDC", "onPendingRegistration")
        }

        override fun onError(error: GigyaError) {
            Log.e("GIGYA-CDC", error.localizedMessage + " Status Code: " + error.statusCode + " Error Code: " + error.errorCode)
        }
    })
}

I've also tried doing this in Java code and got the same results. So my current problem is the sample app works with my keys but when I try to implement the same code it doesn't work.


Solution

  • I found the fix. You need to use strings.xml to define your application id otherwise it doesn't open the Facebook app. Prior to this, I was hardcoding it as eventually I'd need to use gradle.properties to hide the string. This kinda poses a new problem for me because now I need to secure the app id from strings.xml.

    So from:

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

    It became:

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

    To be clear though, the documentation mentioned it was recommended to place it in the strings.xml file but it was never said to be required.