Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

Android Facebook authorization - can not log in when official Facebook app is installed

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.

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.

My code

@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 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");
        }
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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());
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...