我正在使用此代码获取用户详细信息并将其用作登录我的服务器的凭据:
public class FacebookDialog extends Activity {
Facebook facebook = new Facebook("211111915613509");
private SharedPreferences mPrefs;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!(getSharedPreferences(SplashActivity.USER_PREFS, 0).getBoolean(
"fb", false))) {
try {
String s = facebook.logout(this);
} catch (MalformedURLException e) {
} catch (IOException e) {
}
}
/*
* Get existing access_token if any
*/
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);
}
if (expires != 0) {
facebook.setAccessExpires(expires);
}
if (!facebook.isSessionValid()) {
facebook.authorize(this, new String[] {}, new DialogListener() {
@Override
public void onComplete(Bundle values) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires",
facebook.getAccessExpires());
editor.commit();
getFbDetails();
}
@Override
public void onFacebookError(FacebookError error) {
}
@Override
public void onError(DialogError e) {
}
@Override
public void onCancel() {
}
});
} else {
getFbDetails();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
public void onResume() {
super.onResume();
facebook.extendAccessTokenIfNeeded(this, null);
}
}
这很好用。
当用户使用Facebook登录时,我将 fb 设置为 true ;当用户在我的应用中点击退出时, false 。
问题是:
当我退出并再次尝试使用Facebook登录时(我甚至在Facebook应用程序上登出)。我仍然可以获得用户的详细信息。
我在哪里做错了?
我使用facebook.logout()检查 fb 是否为false。
我认为会议没有被清除,怎么做?
谢谢
答案 0 :(得分:2)
试试这个: -
mFacebook.authorize(PlayVideo.this, new String[] {}, Facebook.FORCE_DIALOG_AUTH,new LogoutDialogListener());}
public final class LogoutDialogListener implements DialogListener {
public void onComplete(Bundle values) {
try {
// SessionStore.clear(Login.mFacebook, PlayVideo.this);
Util.clearCookies(PlayVideo.this);
Login.mFacebook.setAccessToken(null);
Login.mFacebook.setAccessExpires(0);
return;
} catch (Exception error) {
Toast.makeText(PlayVideo.this, error.toString(),
Toast.LENGTH_SHORT).show();
}
}
public void onFacebookError(FacebookError error) {
Toast.makeText(PlayVideo.this,
"Something went wrong. Please try again.",
Toast.LENGTH_LONG).show();
}
public void onError(DialogError error) {
Toast.makeText(PlayVideo.this,
"Something went wrong. Please try again.",
Toast.LENGTH_LONG).show();
}
public void onCancel() {
Toast.makeText(PlayVideo.this,
"Something went wrong. Please try again.",
Toast.LENGTH_LONG).show();
}
}
答案 1 :(得分:0)
如果我没记错的话,你可以编辑Facebook SDK中的FbDialog.java(这不是几周前刚刚发布的最新版本,而是前一版)。
我刚从我的代码中删除了这个,我很久以前就改变了。我相信密码行是诀窍行(从第109行开始)......
private void setUpWebView() {
mWebView = new WebView(getContext());
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
mWebView.setWebViewClient(new FbDialog.FbWebViewClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(mUrl);
mWebView.setLayoutParams(FILL);
WebSettings mWebSettings = mWebView.getSettings();
mWebSettings.setSavePassword(false); //RIGHT HERE
mContent.addView(mWebView);
}
这会阻止您的登录持续存在。