[英]Android Facebook SDK Remember Session
I'm writing an application which requires facebook login. 我正在写一个需要登录facebook的应用程序。 I can make user log in when he/she first opens the application. 我可以让用户在他/她第一次打开应用程序时登录。 However, I can't retrieve the session after they restart the application. 但是,我无法在重新启动应用程序后检索会话。 My login code is the following: 我的登录代码如下:
private static Session openActiveSession(Activity activity, boolean allowLoginUI, StatusCallback callback, List<String> permissions) {
OpenRequest openRequest = new OpenRequest(activity).setPermissions(permissions).setCallback(callback);
Session session = new Session.Builder(activity).build();
if (SessionState.CREATED_TOKEN_LOADED.equals(session.getState()) || allowLoginUI) {
Session.setActiveSession(session);
session.openForRead(openRequest);
return session;
}
return null;
}
And I use isLoggedIn
method when the app is opened in order to understand if the user is logged in or not. 并且在打开应用程序时使用isLoggedIn
方法以了解用户是否已登录。
public static boolean isLoggedIn() {
Session session = Session.getActiveSession();
if (session != null && session.isOpened()) {
return true;
} else {
return false;
}
}
But when the application is closed and reopened, this method never returns true
. 但是当应用程序关闭并重新打开时,此方法永远不会返回true
。
How can I retrieve old session back without showing a popup window to want user's facebook account informations, if he/she logged in in the past. 如果他/她过去登录,如何在不显示弹出窗口的情况下检索旧会话以获取用户的Facebook帐户信息。
您可以调用Session.openActiveSessionFromCache,只有在存在缓存的访问令牌时才会打开活动会话,否则返回null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.