Android Studio中Facebook登录OAuth访问令牌签名无效问题求助
Facebook登录集成报错:Invalid OAuth access token signature 解决办法
错误分析
你遇到的是OAuthException(错误码190):无效的OAuth访问令牌签名,本质是Facebook SDK生成的访问令牌无法通过签名验证,绝大多数情况是应用配置信息不匹配导致的。
排查与修复步骤
- 核对应用密钥(App Secret)
确认Firebase控制台「Facebook登录」配置里的App Secret,和Facebook开发者平台「设置-基本」页面的App Secret完全一致,注意不要有空格、大小写错误。 - 验证包名与签名哈希(Key Hash)
- 确保Facebook开发者平台「设置-基本」中Android平台的包名,和你测试应用的包名(
com.example.foodapp)完全一致; - 检查签名哈希:
- 测试环境用debug keystore生成的哈希,生产环境用release keystore生成的哈希,都要添加到Facebook平台的Android配置中;
- 生成debug哈希的命令:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64(Windows路径替换为C:\Users\<你的用户名>\.android\debug.keystore)
- 确保Facebook开发者平台「设置-基本」中Android平台的包名,和你测试应用的包名(
- 确认Firebase与Facebook关联状态
重新检查Firebase控制台「Authentication-登录方法-Facebook」是否已启用,且正确填写了Facebook的App ID和App Secret,保存后重启应用测试。 - 清除残留状态
卸载当前测试应用,清除Facebook客户端缓存,重新安装后发起登录请求,避免旧的无效令牌残留。
代码优化建议
你的核心逻辑没问题,但可以在onError方法中添加日志打印,方便定位更具体的错误:
@Override public void onError(FacebookException exception) { Log.e("FacebookLoginError", exception.getMessage()); Toast.makeText(FacebookAdapter.this, "登录错误:" + exception.getMessage(), Toast.LENGTH_SHORT).show(); }
用户提供的错误日志
2022-08-14 21:34:35.916 28126-28126/com.example.foodapp D/ViewRootImpl[LogIn]: windowFocusChanged hasFocus=true inTouchMode=true 2022-08-14 21:34:36.023 28126-13800/com.example.foodapp E/com.facebook.GraphResponse: {HttpStatus: 400, errorCode: 190, subErrorCode: -1, errorType: OAuthException, errorMessage: Invalid OAuth access token signature.} 2022-08-14 21:34:36.029 28126-13799/com.example.foodapp E/com.facebook.GraphResponse: {HttpStatus: 400, errorCode: 190, subErrorCode: -1, errorType: OAuthException, errorMessage: Invalid OAuth access token signature.} 2022-08-14 21:34:36.031 28126-13796/com.example.foodapp E/com.facebook.GraphResponse: {HttpStatus: 400, errorCode: 190, subErrorCode: -1, errorType: OAuthException, errorMessage: Invalid OAuth access token signature.} 2022-08-14 21:34:36.182 28126-13800/com.example.foodapp E/com.facebook.GraphResponse: {HttpStatus: 400, errorCode: 190, subErrorCode: -1, errorType: OAuthException, errorMessage: Invalid OAuth access token signature.} 2022-08-14 21:34:36.185 28126-13799/com.example.foodapp E/com.facebook.GraphResponse: {HttpStatus: 400, errorCode: 190, subErrorCode: -1, errorType: OAuthException, errorMessage: Invalid OAuth access token signature.} 2022-08-14 21:34:36.325 28126-13799/com.example.foodapp E/com.facebook.GraphResponse: {HttpStatus: 400, errorCode: 190, subErrorCode: -1, errorType: OAuthException, errorMessage: Invalid OAuth access token signature.} 2022-08-14 21:34:36.434 28126-13796/com.example.foodapp E/com.facebook.GraphResponse: {HttpStatus: 400, errorCode: 190, subErrorCode: -1, errorType: OAuthException, errorMessage: Invalid OAuth access token signature.} 2022-08-14 21:34:36.463 28126-13799/com.example.foodapp E/com.facebook.GraphResponse: {HttpStatus: 400, errorCode: 190, subErrorCode: -1, errorType: OAuthException, errorMessage: Invalid OAuth access token signature.} 2022-08-14 21:34:36.598 28126-13799/com.example.foodapp E/com.facebook.GraphResponse: {HttpStatus: 400, errorCode: 190, subErrorCode: -1, errorType: OAuthException, errorMessage: Invalid OAuth access token signature.}
用户提供的核心代码
callbackManager = CallbackManager.Factory.create(); LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile")); LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { handleFacebookAccessToken(loginResult.getAccessToken()); } @Override public void onCancel() { // App code } @Override public void onError(FacebookException exception) { // App code } }); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); callbackManager.onActivityResult(requestCode, resultCode, data); } private void handleFacebookAccessToken(AccessToken token) { AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { FirebaseUser user = mAuth.getCurrentUser(); updateUI(user); } else { Toast.makeText(FacebookAdapter.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); updateUI(null); } } }); } private void updateUI(FirebaseUser user) { Intent intent= new Intent(this,HomeLayout.class); startActivity(intent); }
内容的提问来源于stack exchange,提问作者jaba
相关产品推荐
相关产品推荐

