0

我正在使用此代码获取用户详细信息并将其用作登录我的服务器的凭据:

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 应用程序上注销)。我仍然可以获得用户详细信息。

我在哪里做错了?

我通过检查fb是否为假来使用 facebook.logout()。

我相信会话没有被清除,该怎么做?

谢谢你

4

2 回答 2

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();
    }
}
于 2012-10-30T10:01:15.940 回答
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);
    }

这将阻止您的登录持续存在。

于 2012-10-30T10:09:58.403 回答