简体   繁体   English

Firebase身份验证:1.0.0不适用于Facebook和Twitter

[英]Firebase auth:1.0.0 Not Working for Facebook and Twitter

I'm trying to implement firebase-ui-auth:1.0.0 in my Android App. 我正在尝试在我的Android应用中实现firebase-ui-auth:1.0.0。 I started by downloading and installing the FirebaseUI-Android demo from github ( https://github.com/firebase/FirebaseUI-Android ). 我首先从github( https://github.com/firebase/FirebaseUI-Android )下载并安装FirebaseUI-Android演示。 I have successfully created Firebase users using all four methods (email, Google, Facebook, and Twitter) using this demo app. 我已使用此演示应用程序使用所有四种方法(电子邮件,Google,Facebook和Twitter)成功创建了Firebase用户。

Now I'm trying to implement firebase-ui-auth in my Android App. 现在,我正在尝试在Android应用程序中实现firebase-ui-auth。 The email and Google methods work fine; 电子邮件和Google方法工作正常; the Facebook and Twitter methods fail. Facebook和Twitter方法失败。 When “Sign in with Facebook” is clicked I briefly see the progress bar and then returned to the sign in page with no explanation as to why the sign in failed. 单击“使用Facebook登录”后,我会短暂地看到进度条,然后返回登录页面,而没有说明登录失败的原因。 When “Sign in with Twitter” is clicked, the Twitter page “Authorize myApp to use your account?” appears; 单击“使用Twitter登录”后,将显示Twitter页面“授权myApp使用您的帐户?”; upon clicking “Allow” I return to sign in page and a Toast is shown stating “Unable to complete the action” 单击“允许”后,我将返回登录页面,并显示一条吐司说明“无法完成操作”

I have setup my app in both Facebook and Twitter. 我已经在Facebook和Twitter中设置了我的应用程序。 Inserted both of their App IDs and App secrets into the my App's Firebase console and inserted the Firebase Callback URL in both the Facebook and Twitter consoles. 将他们的应用程序ID和应用程序机密都插入我的应用程序的Firebase控制台中,并将Firebase回调URL插入Facebook和Twitter控制台中。 I've also inserted my Android Key Hash in the Facebook console. 我还将我的Android Key Hash插入了Facebook控制台。

Thanks in advance for any thoughts on how to get the Facebook and Twitter auth working is much appreciated. 在此先感谢您对如何使Facebook和Twitter身份验证有效的任何想法,我们深表感谢。

My app's build.gradle is as follows: 我的应用程序的build.gradle如下:

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
    applicationId "com.lbconsulting.coachslog"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
testCompile 'junit:junit:4.12'

// Google
compile 'com.google.android.gms:play-services-auth:9.8.0'
// Firebase
compile 'com.google.firebase:firebase-database:9.8.0'
compile 'com.google.firebase:firebase-auth:9.8.0'
compile 'com.google.firebase:firebase-config:9.8.0'
compile 'com.google.android.gms:play-services-appinvite:9.8.0'
compile 'com.google.firebase:firebase-messaging:9.8.0'
compile 'com.google.android.gms:play-services-ads:9.8.0'
compile 'com.google.firebase:firebase-crash:9.8.0'
compile 'com.google.firebase:firebase-invites:9.8.0'

// Firebase UI
//    compile 'com.firebaseui:firebase-ui-database:0.4.0'

// FirebaseUI Database only
compile 'com.firebaseui:firebase-ui-database:1.0.0'

// FirebaseUI Auth only
compile 'com.firebaseui:firebase-ui-auth:1.0.0'

// FirebaseUI Storage only
//    compile 'com.firebaseui:firebase-ui-storage:1.0.0'

// Timber and Butterknife
compile 'com.jakewharton.timber:timber:4.1.0'
compile 'com.jakewharton:butterknife:8.0.1'

// Event Bus
compile 'org.greenrobot:eventbus:3.0.0'
// Gson
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
compile 'com.android.support:recyclerview-v7:25.0.0'

// Facebook
compile 'com.facebook.android:facebook-android-sdk:[4,5)'

compile 'org.jetbrains:annotations-java5:15.0'
}
apply plugin: 'com.google.gms.google-services'

In my App's onCreate() I initialize the Firebase Auth with the following code: 在我的应用程序的onCreate()中,我使用以下代码初始化Firebase Auth:

// Initialize Firebase Auth
     mFirebaseAuth = FirebaseAuth.getInstance();
    if (mFirebaseAuth.getCurrentUser() == null) {
        startActivity(AuthUiActivity.createIntent(AthletesActivity.this));
        finish();
        return;
    } else {

My AuthUiActivity code is: 我的AuthUiActivity代码为:

public class AuthUiActivity extends AppCompatActivity {
private static final String FIREBASE_TOS_URL =
        "https://www.firebase.com/terms/terms-of-service.html";

private static final int RC_SIGN_IN = 100;

@BindView(android.R.id.content)
View mRootView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Timber.i("onCreate()");

    FirebaseAuth auth = FirebaseAuth.getInstance();
    if (auth.getCurrentUser() != null) {
        startActivity(AthletesActivity.createIntent(this));
        finish();
    }
    ButterKnife.bind(this);

    startActivityForResult(
            AuthUI.getInstance().createSignInIntentBuilder()
                    .setTheme(AuthUI.getDefaultTheme())
                    .setLogo(AuthUI.NO_LOGO)
                    .setProviders(getSelectedProviders())
                    .setTosUrl(getSelectedTosUrl())
                    .setIsSmartLockEnabled(true)
                    .build(),
            RC_SIGN_IN);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Timber.i("onActivityResult()");
    if (requestCode == RC_SIGN_IN) {
        handleSignInResponse(resultCode, data);
        return;
    }
    showSnackbar(R.string.unknown_response);
}

@MainThread
private void handleSignInResponse(int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        startActivity(AthletesActivity.createIntent(this));
        finish();
        return;
    }

    if (resultCode == RESULT_CANCELED) {
        showSnackbar(R.string.sign_in_cancelled);
        return;
    }

    if (resultCode == ResultCodes.RESULT_NO_NETWORK) {
        showSnackbar(R.string.no_internet_connection);
        return;
    }

    showSnackbar(R.string.unknown_sign_in_response);
}

@MainThread
private List<IdpConfig> getSelectedProviders() {
    List<IdpConfig> selectedProviders = new ArrayList<>();

    selectedProviders.add(new IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build());

    selectedProviders.add(
            new IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER)
                    .setPermissions(getFacebookPermissions())
                    .build());

    selectedProviders.add(
            new IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER)
                    .setPermissions(getGooglePermissions())
                    .build());

    selectedProviders.add(new IdpConfig.Builder(AuthUI.TWITTER_PROVIDER).build());

    return selectedProviders;
}

@MainThread
private List<String> getFacebookPermissions() {
    List<String> result = new ArrayList<>();
    // TODO: do we need to get Facebook user_friends and user_photos
//        result.add("user_friends");
//        result.add("user_photos");
    return result;
}

@MainThread
private List<String> getGooglePermissions() {
    List<String> result = new ArrayList<>();
    // TODO: do we need to get Google Games and Drive_file?
//        result.add(Scopes.GAMES);
//        result.add(Scopes.DRIVE_FILE);
    return result;
}

@MainThread
private String getSelectedTosUrl() {
//        if (mUseGoogleTos.isChecked()) {
//            return GOOGLE_TOS_URL;
//        }
// TODO: create terms of service and save it in Firebase
    return FIREBASE_TOS_URL;
}

@MainThread
private void showSnackbar(@StringRes int errorMessageRes) {
    if (mRootView != null) {
        Snackbar.make(mRootView, errorMessageRes, Snackbar.LENGTH_LONG).show();
    }
}

public static Intent createIntent(Context context) {
    Intent intent = new Intent();
    intent.setClass(context, AuthUiActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}
}

Add the following repository to your gradle: 将以下存储库添加到gradle:

app/build.gradle app / build.gradle

android {
  repositories {
    maven { url 'https://maven.fabric.io/public' }
  }
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter Firebase auth facebook 不工作 - Flutter Firebase auth facebook not working 具有Firebase身份验证的Firebase UI:由于R8,Twitter无法正常工作 - Firebase UI with Firebase Auth : Twitter not working due to R8 失败的firebase身份验证Facebook - Fail firebase auth facebook 如何在 Flutter 中设置 firebase 身份验证(分别使用 ``twitter_login: ^4.0.1`` 和 ``flutter_facebook_auth: ^4.0.1```)? - How to set up firebase Authentication (with ```twitter_login: ^4.0.1``` and ```flutter_facebook_auth: ^4.0.1``` respectively) in Flutter? FireBase Auth createUserWithEmailAndPassword().then() 不起作用 - FireBase Auth createUserWithEmailAndPassword().then() not working com.firebase.ui.auth.FirebaseUiException:提供程序错误 - Firebase-UI 身份验证 Facebook 登录无效 - com.firebase.ui.auth.FirebaseUiException: Provider error - Firebase-UI Authentication Facebook login not working 如何在 Firebase 身份验证中获取 Twitter 屏幕名称 - How to get twitter screen name in Firebase auth 深层链接在Facebook和Twitter中不起作用 - Deep linking not working in facebook and twitter Firebase中的Facebook身份验证无法正常工作 - Facebook authentication in firebase not working Firebase Facebook Twitter提供商getEmail null - Firebase Facebook Twitter Providers getEmail null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM