kingston
kingston

Reputation: 1553

how to logout using facebook api in android

i am using facebook api for android using facebook developer guide. I was able to implement the login for facebook api for android. I want to implement logout function. I have tried following developers guide, but have no idea which place exactly i have to implement. I will be grateful if u guys cud help me out below is the code.

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);
    }

}

Upvotes: 0

Views: 13841

Answers (4)

kevinl
kevinl

Reputation: 4214

with the 3.1 sdk you can call Session.getActiveSession().closeAndClearTokenInformation()

Upvotes: 1

Hardik Gajjar
Hardik Gajjar

Reputation: 5058

facebook.logout(mainActivityContex);

or

facebook.logout(this);

in 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;
}`

Upvotes: 6

Dawid Sajdak
Dawid Sajdak

Reputation: 3084

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;
    }

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

Upvotes: 6

Zsombor Erdődy-Nagy
Zsombor Erdődy-Nagy

Reputation: 16914

There's a .logout() method on that Facebook class if I remember correctly. I think you're looking for that.

Upvotes: 0

Related Questions