Android - Firebase动态Facebook按钮 [英] Android - Firebase Dynamic Facebook button

查看:136
本文介绍了Android - Firebase动态Facebook按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅我的双重发布这个问题,我没有得到答复,我仍然有同样的问题。试图修复它,但没有成功。

我想用Facebook登录按钮来登录我的应用程序。



<现在,当点击 loginbutton 时,我登录并继续第二个活动。

  callbackManager = CallbackManager.Factory.create(); 
LoginButton loginButton =(LoginButton)findViewById(R.id.loginButton);
loginButton.setReadPermissions(email,public_profile);
loginButton.registerCallback(callbackManager,new FacebookCallback< LoginResult>(){
@Override
public void onSuccess(LoginResult loginResult){
Log.d(TAG,facebook:onSuccess :+ loginResult);
handleFacebookAccessToken(loginResult.getAccessToken());
}

@Override
public void onCancel(){
Log。 d(TAG,facebook:onCancel);
// ...
}

@Override
public void onError(FacebookException错误){
Log.d(TAG,facebook:onError,错误);
// ...
}
});

现在在第二项活动中,我有一个按钮 Sign Out 我到第一个活动,并签署我登录我的帐户。代码:

  AuthUI.getInstance()
.signOut(this)
.addOnCompleteListener(new OnCompleteListener< ();
@Override
public void onComplete(@NonNull Task< Void> task){
finish();
}
});

现在,一切正常,除了退出部分。



它注销帐户(我可以在我的日志中看到它)。但是当我回到MainActivity时,动态的Facebook登录按钮仍然表示:退出,而应该已经说用Facebook登录

这是我使用的Facebook按钮:

 < com.facebook.login.widget.LoginButton 
android:id =@ + id / loginButton
android:layout_width =match_parent
android:layout_height =match_parent
android:layout_gravity =center_horizo​​ntal
android:layout_weight =1
android:layout_marginBottom =56dp
android:layout_alignParentBottom =true
android: layout_alignParentStart =true/>

我已经使用了这个,但是找不到任何东西。
尝试将注销方法更改为

  FirebaseAuth.getInstance()。signOut(); 

但是没有任何不同的结果。

我也有同样的不好的经验。最后,我使用 LoginManager 进行Facebook身份验证,并做了如下操作:

  public void logOut(){
FirebaseAuth.getInstance()。signOut();
LoginManager.getInstance()。logOut();
}


Excuse me for double posting this question, I did not get a response and I still have the same problem. Tried to fix it, but wasn't successful. Any help is greatly appreciated.

I want to use the Facebook login button to sign users in to my app.

Now when the loginbutton is clicked, I log in and continue to the 2nd activity.

callbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.loginButton);
    loginButton.setReadPermissions("email", "public_profile");
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "facebook:onSuccess:" + loginResult);
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "facebook:onCancel");
            // ...
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, "facebook:onError", error);
            // ...
        }
    });

Now in the 2nd activity, I have a button Sign Out which returns me to the 1st activity, and sign out my account I signed in with. Code:

        AuthUI.getInstance()
                .signOut(this)
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        finish();
                    }
                });

Now, everything works fine, except for the sign out part.

It does sign out the account (I can see it in my log). But when I get back to the MainActivity, the dynamic Facebook login button still says: Sign out while it should already say Sign in with Facebook.

This is the Facebook button I use:

    <com.facebook.login.widget.LoginButton
    android:id="@+id/loginButton"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal"
    android:layout_weight="1"
    android:layout_marginBottom="56dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true" />

I have googled this, but I could not find anything. Tried to change the sign out method to

FirebaseAuth.getInstance().signOut();

But this was without any different result.

解决方案

I had the same bad experience with that. Finally, I use the LoginManager for Facebook authentication and did something like this:

public void logOut() {
    FirebaseAuth.getInstance().signOut();
    LoginManager.getInstance().logOut();
}

这篇关于Android - Firebase动态Facebook按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆