我在调用 openForPublish 打开带有发布流请求的会话并收到 CLOSED_LOGIN_FAILED 状态时遇到问题。当我尝试在登录对话框中取消时收到此会话状态。当我在 CLOSED_LOGIN_FAILED 状态下再次尝试调用 openForPublish 时,我收到一个异常消息“会话:尝试打开已打开的会话。”。当我检查 session.isOpened 我有 FALSE 并且 isClosed 是 TRUE。
这是我的代码:
Session session = Session.getActiveSession();
if (session == null) {
Log.w("Facebook Session", "TopicShow object is null");
if (savedInstanceState != null) {
Log.w("Facebook Session", "TopicShow Restoring Session");
session = Session.restoreSession(activity, null, fbSessionStateCallback, savedInstanceState);
}
if (session == null) {
session = new Session(activity.getApplicationContext());
}
}
Session.setActiveSession(session);
Log.w("Facebook", "Session inital state when clicked " + session.getState().name());
Log.w("SessionState", "isOpen = " + !session.isOpened() + " isClosed = " + !session.isClosed());
if (!session.isOpened()) {
Log.w("Facebook", "openForRead " + session.getState().name());
/* Prevent it from getting error if no internet. */
OpenRequest request = new Session.OpenRequest(activity);
request.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
request.setPermissions(Arrays.asList("publish_stream"));
request.setCallback(fbPublishRequestStateCallback);
isBlock = false;
session.openForPublish(request);
}
else if (session.isOpened()) {
Request request = Request.newMeRequest(session, graphUserCallback);
request.executeAndWait();
isBlock = true;
}