我一直在我的Android应用中实施Firebase身份验证,并让它轻松运行成功(在调试中签名)为不同的身份验证提供商,如谷歌,但Facebook不会发挥作用。
尝试使用Facebook进行身份验证时,我一直收到com.google.firebase.FirebaseException。我正在使用github上的firebase/quickstart auth app中的示例。从下面的输出中可以看出,Facebook身份验证成功并且是有效的访问令牌。但是,当我将令牌传递给Firebase进行身份验证时,会抛出上述异常。
06-14 00:42:24.704 13275-13275/com.cmpdhoug.logintesting I/FacebookLogin: facebook:onSuccess:com.facebook.login.LoginResult@427332f8
06-14 00:42:24.714 13275-13275/com.cmpdhoug.logintesting I/FacebookLogin: Access token details: {AccessToken token:ACCESS_TOKEN_REMOVED permissions:[user_friends, email, public_profile]}
06-14 00:42:24.714 13275-13275/com.cmpdhoug.logintesting I/FacebookLogin: Token: EAADk2AXUei8BAESARAsZAOCQoZBo1KoLD6GDMDiNUX7U6o92sRZAG5hJN4426JqOYz5p4mYb8yavpTrHlJpoXp7mkCyZCLZAxYy4uSwBC4tK8wbrjccZBkOOS5tgoAbbq0IZBvXVwMV5OUdW1LHMj8PbCMznSzlLageUbpW96Dpa5wk7zVVwFVnsXJZA6flmV98l669VWIkizUpd6OYpeMc4d82JUexPSrYZD
06-14 00:42:24.714 13275-13275/com.cmpdhoug.logintesting I/FacebookLogin: Acc ID: 107700652990130
06-14 00:42:24.714 13275-13275/com.cmpdhoug.logintesting I/FacebookLogin: App ID: 251616461879855
06-14 00:42:24.714 13275-13275/com.cmpdhoug.logintesting I/FacebookLogin: Expires: Sat Aug 13 00:19:00 BST 2016
06-14 00:42:24.714 13275-13275/com.cmpdhoug.logintesting I/FacebookLogin: Last Refresh: Tue Jun 14 00:42:24 BST 2016
06-14 00:42:24.714 13275-13275/com.cmpdhoug.logintesting I/FacebookLogin: Permissions: [user_friends, email, public_profile]
06-14 00:42:24.714 13275-13275/com.cmpdhoug.logintesting I/FacebookLogin: handleFacebookAccessToken:EAADk2AXUei8BAESARAsZAOCQoZBo1KoLD6GDMDiNUX7U6o92sRZAG5hJN4426JqOYz5p4mYb8yavpTrHlJpoXp7mkCyZCLZAxYy4uSwBC4tK8wbrjccZBkOOS5tgoAbbq0IZBvXVwMV5OUdW1LHMj8PbCMznSzlLageUbpW96Dpa5wk7zVVwFVnsXJZA6flmV98l669VWIkizUpd6OYpeMc4d82JUexPSrYZD
06-14 00:42:25.344 13275-13275/com.cmpdhoug.logintesting I/FacebookLogin: signInWithCredential:onComplete:false
06-14 00:42:25.344 13275-13275/com.cmpdhoug.logintesting W/FacebookLogin: signInWithCredential
com.google.firebase.FirebaseException: An internal error has occured. [ Unsuccessful debug_token response from Facebook: {"error":{"message":"Invalid OAuth access token signature.","type":"OAuthException","code":190,"fbtrace_id":"Euly77Ri59w"}} ]
at com.google.android.gms.internal.zzacq.zzbN(Unknown Source)
at com.google.android.gms.internal.zzacn$zzg.zza(Unknown Source)
at com.google.android.gms.internal.zzacy.zzbO(Unknown Source)
at com.google.android.gms.internal.zzacy$zza.onFailure(Unknown Source)
at com.google.android.gms.internal.zzact$zza.onTransact(Unknown Source)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
Facebook errors page会提示访问令牌或登录状态存在问题,但输出确认登录成功且访问令牌正常。我还使用Facebook Access Token debugger确认了令牌有效性,在输出中输入了令牌。
我正在用我尝试的所有东西撞墙砖,我彻底搜索并尝试了很多不同的解决方案,谷歌搜索了几个小时但没有到达任何地方。
FacebookLoginActivity是从MainActivity中的意图启动的。 FacebookLoginActivity的Android代码:
package com.cmpdhoug.logintesting;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FacebookAuthProvider;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
/**
* Demonstrate Firebase Authentication using a Facebook access token.
*/
public class FacebookLoginActivity extends BaseActivity implements
View.OnClickListener {
private static final String TAG = "FacebookLogin";
private TextView mStatusTextView;
private TextView mDetailTextView;
// [START declare_auth]
private FirebaseAuth mAuth;
// [END declare_auth]
// [START declare_auth_listener]
private FirebaseAuth.AuthStateListener mAuthListener;
// [END declare_auth_listener]
private CallbackManager mCallbackManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
setContentView(R.layout.activity_facebook);
// Views
mStatusTextView = (TextView) findViewById(R.id.status);
mDetailTextView = (TextView) findViewById(R.id.detail);
findViewById(R.id.button_facebook_signout).setOnClickListener(this);
// [START initialize_auth]
// Initialize Firebase Auth
mAuth = FirebaseAuth.getInstance();
// [END initialize_auth]
// [START auth_state_listener]
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.i(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.i(TAG, "onAuthStateChanged:signed_out");
}
// [START_EXCLUDE]
updateUI(user);
// [END_EXCLUDE]
}
};
// [END auth_state_listener]
// [START initialize_fblogin]
// Initialize Facebook Login button
mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.button_facebook_login);
loginButton.setReadPermissions("email", "public_profile");
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.i(TAG, "facebook:onSuccess:" + loginResult);
Log.i(TAG, "Access token details: " + loginResult.getAccessToken().toString());
Log.i(TAG,"Token: " + AccessToken.getCurrentAccessToken().getToken());
Log.i(TAG,"Acc ID: " + AccessToken.getCurrentAccessToken().getUserId());
Log.i(TAG,"App ID: " + AccessToken.getCurrentAccessToken().getApplicationId());
Log.i(TAG,"Expires: " + AccessToken.getCurrentAccessToken().getExpires());
Log.i(TAG,"Last Refresh: " + AccessToken.getCurrentAccessToken().getLastRefresh());
Log.i(TAG,"Permissions: " + AccessToken.getCurrentAccessToken().getPermissions());
AccessToken.setCurrentAccessToken(loginResult.getAccessToken());
handleFacebookAccessToken(AccessToken.getCurrentAccessToken());
}
@Override
public void onCancel() {
Log.i(TAG, "facebook:onCancel");
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
@Override
public void onError(FacebookException error) {
Log.i(TAG, "facebook:onError", error);
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
});
// [END initialize_fblogin]
}
// [START on_start_add_listener]
@Override
public void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
// [END on_start_add_listener]
// [START on_stop_remove_listener]
@Override
public void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
// [END on_stop_remove_listener]
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
// [START auth_with_facebook]
private void handleFacebookAccessToken(AccessToken token) {
Log.i(TAG, "handleFacebookAccessToken:" + token);
// [START_EXCLUDE silent]
showProgressDialog();
// [END_EXCLUDE]
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.i(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(FacebookLoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// [START_EXCLUDE]
hideProgressDialog();
// [END_EXCLUDE]
}
});
}
// [END auth_with_facebook]
public void signOut() {
mAuth.signOut();
LoginManager.getInstance().logOut();
updateUI(null);
}
private void updateUI(FirebaseUser user) {
hideProgressDialog();
if (user != null) {
mStatusTextView.setText(getString(R.string.facebook_status_fmt, user.getDisplayName()));
mDetailTextView.setText(getString(R.string.firebase_status_fmt, user.getUid()));
findViewById(R.id.button_facebook_login).setVisibility(View.GONE);
findViewById(R.id.button_facebook_signout).setVisibility(View.VISIBLE);
} else {
mStatusTextView.setText(R.string.signed_out);
mDetailTextView.setText(null);
findViewById(R.id.button_facebook_login).setVisibility(View.VISIBLE);
findViewById(R.id.button_facebook_signout).setVisibility(View.GONE);
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button_facebook_signout:
signOut();
break;
}
}
}
Android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cmpdhoug.logintesting">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<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="@string/fb_login_protocol_scheme" />
</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"/>
<activity android:name=".EmailPassword">
</activity>
<activity android:name=".GoogleSignIn">
</activity>
<activity android:name=".FacebookLogin">
</activity>
<activity android:name=".FacebookLoginActivity">
</activity>
</application>
</manifest>
任何帮助表示感谢。
答案 0 :(得分:1)
您可以查看您的Facebook App ID&amp; Firebase控制台中的密码设置是否正确?如果是,请在https://firebase.google.com/support/contact/bugs-features/
上提交Firebase身份验证错误答案 1 :(得分:1)
您最有可能在Firebase帐户中输入错误的应用凭据。请尝试再次复制它们。 关怀: - Facebook在设置标签中隐藏了应用秘密。单击show然后将其复制到您的firebase帐户,否则它将显示相同的错误。