Android应用Facebook登录遇Firebase无效hash key及debug_token失败问题求助
Fixing Facebook Login Issues on Android: Debug Token & Invalid Hash Key Problems
Hey there, let’s work through those frustrating Facebook Login bugs you’re hitting—these are super common, but easy to fix once you nail down the details!
1. Fixing "Facebook Login Unsuccessful debug_token response from Facebook"
Here are the most likely fixes for this error:
- Verify your App ID/Secret & Token Validity
Double-check that the App ID and App Secret in your Facebook Developer Dashboard match exactly what’s in your Android project (look for thecom.facebook.sdk.ApplicationIdmeta-data in yourAndroidManifest.xml). You can validate the debug token directly using Facebook’s Graph API:
The response will tell you if the token is expired, tied to the wrong app, or invalid for another reason.GET /debug_token?input_token={your_debug_token}&access_token={your_app_id}|{your_app_secret} - Check Login Product Configuration
In the Facebook Developer Dashboard, navigate to your app’s "Login with Facebook" product settings. Make sure:- The
Valid OAuth Redirect URIsis set tofb{your_app_id}://authorize(replace{your_app_id}with your actual ID) - Required toggles like "Embedded Browser OAuth Login" are enabled (this is needed for in-app login flows)
- The
- Confirm SDK Initialization
Ensure you’re initializing the Facebook SDK correctly in your Application class (or main activity):
A missing or misconfigured initialization can cause token validation failures.FacebookSdk.sdkInitialize(getApplicationContext());
2. Fixing "Invalid hash key when trying to login using Facebook" (Both Debug & Release Scenarios)
Hash keys are tied to your app’s signing certificate—debug and release builds use different certificates, so you need to add both to Facebook’s dashboard.
For Android Studio-installed (Debug) Apps
- Regenerate the Debug Hash Key
Run this command in Android Studio’s Terminal (use the correct one for your OS):- Mac/Linux:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 - Windows:
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64
android. Copy the generated base64 hash and add it to your app’s "Android" platform settings in the Facebook Developer Dashboard under "Key Hashes". - Mac/Linux:
- Confirm Debug Keystore Path
If you’ve customized your debug keystore, check the path in Android Studio viaFile > Project Structure > Modules > Signing Configs > Debug. Update the command above to use this custom path if needed.
For Play Store-installed (Release) Apps
- Use Play App Signing Hash (If Enabled)
Most apps use Google Play’s App Signing feature now. To get the correct hash:- Open the Google Play Console, go to your app >
Release > Setup > App signing - Copy the
SHA-1 certificate fingerprintfrom the "App signing certificate" section - Convert this SHA-1 hex string to base64 (you can use a local command line tool or a simple converter script)
- Add this base64 hash to Facebook’s "Key Hashes" list
- Open the Google Play Console, go to your app >
- For Custom Release Keystores
If you’re not using Play App Signing, generate the hash from your own release keystore with this command (replace placeholders):
Enter your keystore password when prompted, then add the resulting hash to Facebook’s dashboard.keytool -exportcert -alias {your_release_alias} -keystore {path_to_release_keystore} | openssl sha1 -binary | openssl base64 - Double-Check Package & Class Names
In Facebook’s Android platform settings, ensure thePackage Namematches exactly what’s in yourAndroidManifest.xml, and theClass Nameis the full path to your Login Activity (e.g.,com.yourcompany.yourapp.LoginActivity).
内容的提问来源于stack exchange,提问作者Andrey Dobrikov
相关产品推荐
相关产品推荐

