Login Facebook with one activity and logout it with another activity

怎甘沉沦 提交于 2019-12-12 04:48:44

问题


I am using Facebook login with app. I got successful login from app to facebook and logout is not working. I am using facebook sdk 3.0 and declare all permission in mainifest.xml. Here is logout button code.

public void logoutFromFacebook() {
    mAsyncRunner.logout(this, new RequestListener() {
        @Override
        public void onComplete(String response, Object state) {

            Log.d("Logout from Facebook", response);

            if (Boolean.parseBoolean(response) == true) {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        btnFbLogin.setVisibility(View.VISIBLE);
                        finish();
                        btnFbGetProfile.setVisibility(View.INVISIBLE);

                    }

                });

            }
        }

        @Override
        public void onIOException(IOException e, Object state) {
        }

        @Override
        public void onFileNotFoundException(FileNotFoundException e,
                Object state) {
        }

        @Override
        public void onMalformedURLException(MalformedURLException e,
                Object state) {
        }

        @Override
        public void onFacebookError(FacebookError e, Object state) {
        }
    });
}

Help please and thanks in advance.


回答1:


this method works for me

public static void LogoutFB(Context context) {
    Session session = Session.getActiveSession();
    if (session != null) {

        if (!session.isClosed()) {
            session.closeAndClearTokenInformation();
            //clear your preferences if saved
        }
    } else {

        session = new Session(context);
        Session.setActiveSession(session);

        session.closeAndClearTokenInformation();
            //clear your preferences if saved

    }

}



回答2:


i used this one its working

// log out from facebook    

public static void callFacebookLogout(Context context) {
    Session session = Session.getActiveSession();
    if (session != null) {

        if (!session.isClosed()) {
            session.closeAndClearTokenInformation();
            // clear your preferences if saved
        }
    } else {
        session = new Session(context);
        Session.setActiveSession(session);
        session.closeAndClearTokenInformation();
        // clear your preferences if saved
    }
}


来源:https://stackoverflow.com/questions/27183682/login-facebook-with-one-activity-and-logout-it-with-another-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!