我已使用以下代码进行 Facebook 身份验证,它工作正常,但是当我取消身份验证并尝试再次进行身份验证时,应用程序崩溃并且日志是由以下原因引起的:java.lang.UnsupportedOperationException: Session: an attempt was made to open an already opened session.
调试时我得到了这样
{Session state:CREATED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[]}, appId:xxxxxxxxxxxxxxx}
我该如何解决这个问题。请帮助我。在此先感谢
private void askFacebbokAuthentication() {
Session session = Session.getActiveSession();
if (session.isOpened()) {
facebook = true;
if (!hasPublishPermission()) {
session.requestNewPublishPermissions(new NewPermissionsRequest(
MyActivity.this, PERMISSIONS));
}
} else {
Session.OpenRequest openRequest = null;
openRequest = new Session.OpenRequest(MyActivity.this);
if (openRequest != null) {
openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
if (!hasPublishPermission()) {
openRequest.setPermissions(PERMISSIONS);
}
session.openForPublish(openRequest);
}
}
}