使用 Facebook SDK 创建打开请求时,出现以下错误。
错误:
引起:java.lang.UnsupportedOperationException:会话:试图打开一个已经打开的会话。在 com.facebook.Session.open(Session.java:985) 在 com.facebook.Session.openForRead(Session.java:388) 在 com.photos.pixitor.activities.PhotoEffectBaseActivity.loginRequest(PhotoEffectBaseActivity.java:619)
如果我首先提出请求,则不会发生错误。但是在先发出登录请求然后取消请求并再次主登录请求后,应用程序崩溃了。
这是代码:
OpenRequest 请求 = new Session.OpenRequest(this); request.setPermissions(Arrays.asList("basic_info"));
if(session.isOpened()){
session.requestNewReadPermissions(new NewPermissionsRequest(
PhotoEffectBaseActivity.this,"basic_info"));
session.addCallback(new StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if(state.isOpened()){
Util.logd("Opened+Publishing Request");
publishPhotoRequest(session);
}
if(session.isOpened()){
Util.logd("Session is Opened");
getUserDetails(session);
}
}
});
return session;
}
Util.logd("Session Not Opened: Opening For Read");
session.openForRead(request);
Util.logd("Session is Opened for Read");
session.addCallback(new StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if(state.isOpened()){
Util.logd("Opened+Publishing Request");
publishPhotoRequest(session);
}
if(session.isOpened()){
Util.logd("Session is Opened");
getUserDetails(session);
}
}
});