android - Can't logout from facebook session -
i have created facebook integrate application. can login , logout correctly no problems, , when login , close app re-open can logout correctly. problem when login run application eclipse can't logout. shows errors.
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); facebook = new facebook(app_id); masyncrunner = new asyncfacebookrunner(facebook); sharepref = getpreferences(mode_private); facebook.setaccesstoken(sharepref.getstring(access_token, null)); facebook.setaccessexpires(sharepref.getlong(expire_session, 0)); buttonlogin.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { logintofacebook(); } }); buttonlogout.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { logoutfacebook(); } }); } public void logintofacebook() { if (!facebook.issessionvalid()) { facebook.authorize(this, permissions, facebook.force_dialog_auth, new dialoglistener() { @override public void onfacebookerror(facebookerror e) { } @override public void onerror(dialogerror e) { } @override public void oncomplete(bundle values) { sharedpreferences.editor editor = sharepref.edit(); editor.putstring(access_token, facebook.getaccesstoken()); editor.putlong(expire_session, facebook.getaccessexpires()); editor.commit(); } @override public void oncancel() { } }); } else { toast.maketext(getapplicationcontext(), "you login", toast.length_short).show(); } } protected void logoutfacebook() { if (facebook.issessionvalid()) { masyncrunner.logout(this, new requestlistener() { @override public void oncomplete(string response, object state) { log.d("logout facebook", response); if (boolean.parseboolean(response) == true) { log.e("logout facebook", "great"); } } @override public void onioexception(ioexception e, object state) { } @override public void onfilenotfoundexception( filenotfoundexception e, object state) { } @override public void onmalformedurlexception( malformedurlexception e, object state) { } @override public void onfacebookerror(facebookerror e, object state) { } }); } else { toast.maketext(getapplicationcontext(), "login first", toast.length_short).show(); } }
i got type of error:
e/androidruntime( 6331): fatal exception: thread-264 e/androidruntime( 6331): java.lang.illegalargumentexception: invalid context argument e/androidruntime( 6331): @ android.webkit.cookiesyncmanager.createinstance(cookiesyncmanager.java:86) e/androidruntime( 6331): @ com.facebook.internal.utility.clearcookiesfordomain(utility.java:261) e/androidruntime( 6331): @ com.facebook.internal.utility.clearfacebookcookies(utility.java:285) e/androidruntime( 6331): @ com.facebook.session.closeandcleartokeninformation(session.java:593) e/androidruntime( 6331): @ com.facebook.android.facebook.logoutimpl(facebook.java:698) e/androidruntime( 6331): @ com.facebook.android.asyncfacebookrunner$1.run(asyncfacebookrunner.java:89) w/activitymanager( 1202): force finishing activity com.facebook.androidhive/.androidfacebookconnectactivity w/windowmanager( 1202): failure taking screenshot (246x437) layer 21020 w/trace ( 6331): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 6239): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 6331): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 6239): unexpected value nativegetenabledtags: 0 w/trace ( 6239): unexpected value nativegetenabledtags: 0 w/trace ( 6239): unexpected value nativegetenabledtags: 0 w/trace ( 6239): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 e/surfaceflinger( 786): ro.sf.lcd_density must defined build property w/trace ( 6239): unexpected value nativegetenabledtags: 0 w/trace ( 6239): unexpected value nativegetenabledtags: 0 w/trace ( 6239): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 6239): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 6331): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 6239): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0 w/trace ( 1202): unexpected value nativegetenabledtags: 0
try this..
delete below lines mainactivity..
sharepref = getpreferences(mode_private); facebook.setaccesstoken(sharepref.getstring(access_token, null)); facebook.setaccessexpires(sharepref.getlong(expire_session, 0));
and add below lines inside in login function
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); toast.maketext(getapplicationcontext(), "you login", toast.length_short).show(); } if (expires != 0) { facebook.setaccessexpires(expires); toast.maketext(getapplicationcontext(), "you login", toast.length_short).show(); }
Comments
Post a Comment