用于android facebook连接的按钮注销

时间:2012-09-13 03:06:41

标签: android facebook facebook-android-sdk

需要帮助 - 我有一些像这样的退出代码

public void logoutFromFacebook() {
    mAsyncRunner.logout(this, new RequestListener() {

        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() {
                    // Login button visible
                    btnFbLogin.setVisibility(View.VISIBLE);
                    // making all remaining buttons invisible
                    btnFbGetProfile.setVisibility(View.INVISIBLE);
                    btnPostToWall.setVisibility(View.INVISIBLE);
                    btnShowAccessTokens.setVisibility(View.INVISIBLE);
                    btnFbLogout.setVisibility(View.INVISIBLE);
                }
            });
        }
    }
}

但是那个代码没有用,当我点击退出,然后再次点击登录,我没有再输入用户名和密码,我想如果我点击退出,当我再次点击登录时,我可以再次输入用户名和密码,请你需要解决方案,谢谢

1 个答案:

答案 0 :(得分:1)

当用户按下注销按钮时,您必须以这种方式使用,您必须执行此代码

  public void runTestLogout() {
    if (testLogout()) {
        logoutText.setText("Logout Tests Passed");
    } else {
        logoutText.setText("Logout Tests Failed");
    }
}



 public boolean testLogout() {
    try {
        Log.d("Tests", "Testing logout");
        String response = authenticatedFacebook.logout(this);
        Log.d("Tests", "Got logout response: *" + response + "*");
        if (!response.equals("true")) {
            return false;
        }

        Log.d("Tests", "Testing logout on logged out facebook session");
        try {
            Util.parseJson(authenticatedFacebook.logout(this));
            return false;
        } catch (FacebookError e) {
            if (e.getErrorCode() != 101 || 
                    !e.getMessage().equals("Invalid API key") ) {
                return false;
            }
        }

        Log.d("Tests", "Testing logout on unauthenticated object");
        try {
            Util.parseJson(new Facebook(APP_ID).logout(this));
            return false;
        } catch (FacebookError e) {
            if (e.getErrorCode() != 101 || 
                    !e.getMessage().equals("Invalid API key") ) {
                return false;
            }
        }

        Log.d("Tests", "All Logout Tests Passed");
        return true;
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    }
}

主要是

  String response = authenticatedFacebook.logout(this);

通过运行此代码,您将注销,现在您可以再次登录,您将获得空的用户名和密码按钮