简体   繁体   中英

Android Facebook key hash — “remote_app_id does not match stored id”

I am trying to implement Facebook log in and then allow the user to post status updates and share details to Facebook through the app. I (think) the user is not successfully able to log into Facebook. Below is the process the user goes through:

  • User clicks Login button
  • User logs in successfully
  • Below window appears to user

状态图片

  • When the user hits the Share button, this error message appears: (#404) remote_app_id does not match stored id

I have gotten the Key Hashes for my debug keystore and release keystore using the below 2 command lines.

Debug Keystore

keytool -exportcert -alias androiddebugkey -keystore C:\Users\lyonsmg\.android\debug.keystore | C:\OpenSSL-Win64\bin\openssl.exe sha1 -binary | C:\OpenSSL-Win64\bin\openssl.exe base64

Release Keystore

keytool -exportcert -alias C:\Users\lyonsmg\matt\_keystores_and_passwords\BibleTriviaLite_keystore -keystore C:\Users\lyonsmg\matt\_keystores_and_passwords\BibleTriviaLite_keystore | C:\OpenSSL-Win64\bin\openssl.exe sha1 -binary | C:\OpenSSL-Win64\bin\openssl.exe

I used android as the password for the debug keystore and my private password for the release keystore. I placed both of the resulting key hashes in Developers Settings on Facebook and also in Facebook App Dashboard. Its the 2 places that the Facebook Android SDK docs tell me to put it.

I have my app_id that is found in the Facebook App Dashboard in my Android Manifest . Below is my Android Manifest and you can see the 2 spots where my app_id is found. You can find it in the code as @string/app_id .

Android Manifest

<manifest 
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="matt.lyons.bibletrivia.lite"
    android:versionCode="13"
    android:versionName="2.1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:icon="@drawable/icon_blue_bg"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.gms.games.APP_ID"
            android:value="@string/app_id" />
        <activity
            android:name=".SplashScreen"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action
                    android:name="android.intent.action.MAIN" />
                <category
                    android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:name="com.google.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
        <activity
            android:label="@string/app_name"
            android:name=".About"
            android:screenOrientation="portrait" />
        <activity
            android:label="@string/app_name"
            android:name=".Categories"
            android:screenOrientation="portrait" />
        <activity
            android:label="@string/app_name"
            android:name=".Question"
            android:screenOrientation="portrait" />
        <activity
            android:label="@string/app_name"
            android:name=".Quiz"
            android:screenOrientation="portrait" />
        <activity
            android:label="@string/app_name"
            android:name=".QuestionView"
            android:screenOrientation="portrait" />
        <activity
            android:label="@string/app_name"
            android:name=".Results"
            android:screenOrientation="portrait" />
        <activity
            android:label="@string/app_name"
            android:name=".Highscores"
            android:screenOrientation="portrait" />
        <activity
            android:label="@string/app_name"
            android:name=".DatabaseHelper"
            android:screenOrientation="portrait" />
        <activity
            android:label="@string/app_name"
            android:name=".ComingSoon"
            android:screenOrientation="portrait" />
        <activity
            android:label="@string/app_name"
            android:name=".MainMenu"
            android:screenOrientation="portrait" />
        <activity
            android:label="@string/app_name"
            android:name=".MyApplication"
            android:screenOrientation="portrait" />
        <activity
            android:label="@string/app_name"
            android:name=".Levels"
            android:screenOrientation="portrait" />
        <activity
            android:label="@string/app_name"
            android:name=".GameType"
            android:screenOrientation="portrait" />
        <meta-data android:value="@string/app_id" android:name="com.facebook.sdk.ApplicationId"/>
        <activity android:label="@string/app_name" android:name="com.facebook.LoginActivity"></activity>
    </application>

    <uses-permission 
        android:name="android.permission.INTERNET" />
    <uses-permission 
        android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission 
        android:name="com.android.vending.BILLING" />
</manifest>

Sorry I wrote so much but I was just trying to cover all my bases and be thorough! My question is, what am I doing wrong? Why is it telling me that my "remote_app_id" does not match my "stored id"?

You're using the same value="@string/app_id" for both com.google.android.gms.games.APP_ID and com.facebook.sdk.ApplicationId .

Your Facebook app ID can't possibly be the same as your Google app ID. You need to get the Facebook app ID from the Facebook App Dashboard.

I was facing the same problem, the hash code that i generated through openssl was wrong i then used this function and it help. Hope it help you all too.

private void printKeyHash() {
    // Add code to print out the key hash
    try {
        PackageInfo info = getPackageManager().getPackageInfo("YOUR PACKAGE NAME", PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {
        Log.e("KeyHash:", e.toString());
    } catch (NoSuchAlgorithmException e) {
        Log.e("KeyHash:", e.toString());
    }
}

Use the hash code that is printed in logs and enjoy. Happy Coding :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM