本文介绍了Android Facebook授权 - 安装官方的Facebook应用程序时无法登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要登录到Facebook并获得像电子邮件等相同的字段。我使用的是Facebook SDK,并在developer.facebook中设置了我的Android键哈希,并设置了配置为Android SSO。在模拟器和一些设备中,应用程序工作正常。

I need to log in to Facebook and get same fields like email, etc. I use the Facebook SDK, and I set my Android key Hash in developers.facebook and set "Configured for Android SSO". In the simulator and some devices the application works fine.

但是,如果设备上安装了官方的Facebook应用程序,我的应用程序不起作用:我按下登录按钮,但是我看不到有一个网页视图的对话框是我的密码和登录被要求。它看起来像堆栈溢出问题 或堆栈溢出问题 ,但我无法理解如何解决

But if the official Facebook application is installed on the device, my application does not work: I push the login button, but I not see a dialog with a web-view were my password and login are asked for. It looks like the problem in Stack Overflow question Using facebook.authorize with the Android SDK does not call onActivityResult or Stack Overflow question Android Facebook API single sign-on?, but I can not understand how to resolve it.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    this.facebookConnector.getFacebook().authorizeCallback(requestCode, resultCode, data);
}

public void getAccessToken() {
    SessionEvents.AuthListener listener = new SessionEvents.AuthListener() {
        @Override
        public void onAuthSucceed() {
            setupAccessToken(facebookConnector.getFacebook().getAccessToken());
        }

        @Override
        public void onAuthFail(String error) {
            Toast.makeText(getApplicationContext(), getString(R.string.error_login), Toast.LENGTH_SHORT).show();
        }
    };

    SessionEvents.addAuthListener(listener);
    facebookConnector.login();
}



facebookConnector代码



facebookConnector code

public class FacebookConnector {
    public void login() {
        if (!facebook.isSessionValid()) {
            facebook.authorize(this.activity, this.permissions, new LoginDialogListener());
        }
    }

    private final class LoginDialogListener implements DialogListener {
        public void onComplete(Bundle values) {
            SessionEvents.onLoginSuccess();
        }

        public void onFacebookError(FacebookError error) {
            SessionEvents.onLoginError(error.getMessage());
        }

        public void onError(DialogError error) {
            SessionEvents.onLoginError(error.getMessage());
        }

        public void onCancel() {
            SessionEvents.onLoginError("Action Canceled");
        }
    }
}


推荐答案

请更新您的应用程序的以下代码。这将解决您的问题。

Please update the below code of your application. It will solve your problem.

public void loginAndPostToWall() {
    facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH,
            new LoginDialogListener());
}

这篇关于Android Facebook授权 - 安装官方的Facebook应用程序时无法登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:23