android - Facebook SDK 3 - Session Re-log in issue -
i'm using facebook login described in "getting started" document - https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/
// start facebook login session.openactivesession(this, true, new session.statuscallback() { // callback when session changes state @override public void call(session session, sessionstate state, exception exception) { if (session.isopened()) { // make request /me api request.executemerequestasync(session, new request.graphusercallback() { // callback after graph api response user object @override public void oncompleted(graphuser user, response response) { if (user != null) { textview welcome = (textview) findviewbyid(r.id.welcome); welcome.settext("hello " + user.getname() + "!"); } } }); } } });
when using code facebook recognize user (that loged-in in facebook app) , assumes user want log in with.
let's want leave decision facebook account use user. how can that?
things i've tried far:
1)perform user log in this:
sessiontracker sessiontracker = new sessiontracker(activity, new statuscallback() { @override public void call(session session, sessionstate state, exception exception) { } }, null, false); if (sessiontracker.getsession() == null || sessiontracker.getsession().getstate().isclosed()) { sessiontracker.setsession(null); session session = new session.builder(activity).setapplicationid(activity.getstring(r.string.fb_app_id)).build(); session.setactivesession(session); } final session currentsession = sessiontracker.getsession(); if (!currentsession.isopened()) { session.openrequest openrequest = null; openrequest = new session.openrequest(activity); if (openrequest != null) { openrequest.setdefaultaudience(sessiondefaultaudience.friends); openrequest.setpermissions(arrays.aslist("email", "publish_actions")); openrequest.setloginbehavior(sessionloginbehavior.suppress_sso); openrequest.setcallback(new statuscallback() { @override public void call(session session, sessionstate state, exception exception) { request.executemerequestasync(currentsession, new request.graphusercallback() { @override public void oncompleted(graphuser user, response response) { authlistener.oncompleteauthorization(user != null, user, currentsession.getaccesstoken(), currentsession.getexpirationdate().gettime()); } }); } }); currentsession.openforpublish(openrequest);
this works fine first time, second time been called (let's after user loggin out app, , want re-login facebook account) remembers last user logged in. !!even after uninstall facebook app , app!!!!
2) calling same code before log in again:
if (session.getactivesession() != null) { session.getactivesession().closeandcleartokeninformation(); }
it not anything...
please me understand how can clear previous facebook user history / cached tokens, achieve following behavior: every time user perform facebook login - facebook "enter email + password" dialog appear...
thanks in advance..
first of all, not use sessiontracker directly. it's not public class, , not meant consumed directly.
secondly, if want pop email/password dialog every time, need disable sso login. can have inside switchusersample how multiple sessions, here's gist of it:
session s = new session(this); session.setactivesession(s); session.openrequest request = new session.openrequest(this); request.setpermissions(...); // note cannot set email , publish_actions in same request request.setloginbehavior(sessionloginbehavior.suppress_sso); request.setcallback(...); s.openforread(request);
some time later, in callback, should check if session opened, , if contains publish_actions permission, , if not request additional publish permissions (see scrumptious sample example).
lastly, when user logs out, call closeandcleartokeninformation() method you've done previously. since you're forcing dialog login now, work expect to.
Comments
Post a Comment