如何在android中使用facebook api注销

时间:2011-11-30 09:11:31

标签: java android facebook-graph-api

我使用facebook开发者指南使用facebook api for android。我能够实现facebook api for android的登录。我想实现注销功能。我试过跟随开发者指南,但不知道我必须实现哪个地方。如果你们帮我解决下面的代码,我将不胜感激。

public class FacebookandroidsdkActivity extends Activity {
    /** Called when the activity is first created. */

    Facebook facebook = new Facebook("252039928190210");
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        facebook.authorize(this, new DialogListener() {
            @Override
            public void onComplete(Bundle values) {}

            @Override
            public void onFacebookError(FacebookError error) {}

            @Override
            public void onError(DialogError e) {}

            @Override
            public void onCancel() {}
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        facebook.authorizeCallback(requestCode, resultCode, data);
    }

}

4 个答案:

答案 0 :(得分:6)

public String logout(Context context)
            throws MalformedURLException, IOException {
        Util.clearCookies(context);
        Bundle b = new Bundle();
        b.putString("method", "auth.expireSession");
        String response = request(b);
        setAccessToken(null);
        setAccessExpires(0);
        return response;
    }

自: https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/android/Facebook.java

答案 1 :(得分:6)

facebook.logout(mainActivityContex);

facebook.logout(this);
在Facebook SDK中

Facebook.java --`

public String logout(Context context)
        throws MalformedURLException, IOException {
    Util.clearCookies(context);
    Bundle b = new Bundle();
    b.putString("method", "auth.expireSession");
    String response = request(b);
    setAccessToken(null);
    setAccessExpires(0);
    return response;
}`

答案 2 :(得分:1)

使用3.1 sdk

可以调用Session.getActiveSession()。closeAndClearTokenInformation()

答案 3 :(得分:0)

如果我没记错的话,那个Facebook类上有一个.logout()方法。我想你正在寻找那个。