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

后端 未结 4 1300
予麋鹿
予麋鹿 2020-11-29 12:03

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 Andro

相关标签:
4条回答
  • 2020-11-29 12:44

    I had the same problem like you. Finally, I solved using this:

    Open Facebook.java provided by the Facebook SDK and then change it like this:

    public void authorize(Activity activity, String[] permissions,
                          int activityCode, final DialogListener listener) {
        boolean singleSignOnStarted = false;
    
        mAuthDialogListener = listener;
    
        /*
        // Prefer single sign-on, where available.
        if (activityCode >= 0) {
            singleSignOnStarted = startSingleSignOn(activity, mAppId,
                                                    permissions, activityCode);
        }
        // Otherwise fall back to the traditional dialog.
        if (!singleSignOnStarted) {
        */
    
        startDialogAuth(activity, permissions);
    
        // }
    }
    
    0 讨论(0)
  • 2020-11-29 12:57

    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());
    }
    
    0 讨论(0)
  • 2020-11-29 13:00

    This is just a wild guess, but instead of this:

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

    Try:

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

    Since you're not calling the parent method some things might not work as expected...

    0 讨论(0)
  • 2020-11-29 13:05
    private static Session openActiveSession(Activity activity, boolean allowLoginUI, StatusCallback callback, List<String> permissions) {
        OpenRequest openRequest = new OpenRequest(activity).setPermissions(permissions).setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO).setCallback(callback);
        Session session = new Session.Builder(activity).build();
        if (SessionState.CREATED_TOKEN_LOADED.equals(session.getState()) || allowLoginUI) {
            Session.setActiveSession(session);
            session.openForRead(openRequest);
            return session;
        }
        return null;
    }
    

    Edit your openactivesession function like this

    0 讨论(0)
提交回复
热议问题