简体   繁体   中英

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

}
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

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

使用3.1 SDK可以调用Session.getActiveSession()。closeAndClearTokenInformation()

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM