无法在Android应用程序中从Facebook注销

时间:2014-01-06 05:29:21

标签: android android-facebook

我已经尝试通过facebook成功整合身份验证,但是我从facebook的注销无法正常工作。以下代码片段是我的facebook登录功能

        public void loginToFacebook() {

    mPrefs = getPreferences(MODE_PRIVATE);
    String access_token = mPrefs.getString("access_token", null);
    long expires = mPrefs.getLong("access_expires", 0);
    if (access_token != null) {
        facebook.setAccessToken(access_token);
        getProfileInformation();
        Log.d("FB Sessions", "" + facebook.isSessionValid());
    }
    if (expires != 0) {
        facebook.setAccessExpires(expires);
    }
    if (!facebook.isSessionValid()) {
        facebook.authorize(this,
                new String[] { "email", "publish_stream" },
                new DialogListener() {
                    @Override
                    public void onCancel() {
                        // Function to handle cancel event
                    }

                    @Override
                    public void onComplete(Bundle values) {
                        // Function to handle complete event
                        // Edit Preferences and update facebook acess_token
                        SharedPreferences.Editor editor = mPrefs.edit();
                        editor.putString("access_token",
                                facebook.getAccessToken());
                        editor.putLong("access_expires",
                                facebook.getAccessExpires());
                        editor.commit();
                        getProfileInformation();
                    }
                });
    }
}

以下是注销功能

@SuppressWarnings("deprecation")
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() {
                        SharedPreferences.Editor editor = mPrefs.edit();

                        editor.clear();
                        editor.commit();
                    }
                });
            }
        }
    });
}

如何以正确的方式进行注销功能。请重播...

1 个答案:

答案 0 :(得分:1)

Session session = Session.getActiveSession();
session.closeAndClearTokenInformation();

请尝试注销。