Use this code:
fb_logout.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
fb_Logout();
}
});
public boolean fb_Logout() {
Toast.makeText(getApplicationContext(),
"You are logged out from Facebook.", Toast.LENGTH_LONG).show();
try {
Log.d("Tests", "Testing logout");
String response = authenticatedFacebook.logout(this);
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;
}
}
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;
}
}
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…