我正在使用 Facebook 登录,如“入门”文档中所述 -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 to the /me API
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
// callback after Graph API response with 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() + "!");
}
}
});
}
}
});
使用此代码时,Facebook 会识别用户(在 Facebook 应用程序中登录的用户)并假定这是我要登录的用户。
假设我想将决定使用哪个 Facebook 帐户留给用户。 我怎样才能做到这一点?
到目前为止我尝试过的事情:
1)像这样执行用户登录:
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);
这第一次工作正常,但第二次被调用(假设用户从我的应用程序注销,并想用另一个 Facebook 帐户重新登录)它会记住最后一个登录的用户。!!即使在卸载后Facebook 应用程序和我的应用程序!!!!
2)再次登录前调用相同的代码:
if (Session.getActiveSession() != null) {
Session.getActiveSession().closeAndClearTokenInformation();
}
它什么也没做……
请帮助我了解如何清除所有以前的 Facebook 用户历史记录/缓存的令牌,以实现以下行为:每次用户执行 Facebook 登录 - Facebook“输入电子邮件+密码”对话框将出现...
提前致谢..