这是我更新状态的代码:
new Session(context);
Session.setActiveSession(session);
Session.openActiveSession(context);
Log.e("session after setted",Session.getActiveSession().toString());
Request request = Request.newMeRequest(Session.getActiveSession(), new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
// If the response is successful
if (Session.getActiveSession().isOpened()) {
if (user != null) {
session = Session.getActiveSession();
postFromAlarm();
Log.e("user","not null");
}else{
postFromAlarm();
Log.e("user","null");
}
} else{
postFromAlarm();
Log.e("not open session",Session.getActiveSession().toString());
Log.e("session","not open");
}
}
});
Log.e("request session",request.getSession().toString());
Request.executeBatchAsync(request);
Log.e("session after setted",Session.getActiveSession().toString());
正在显示一个良好且健康的会话,可用于发布。因为在logcat中显示会话打开了,accesstoken好,app_id也好。
但是当我尝试发布时使用此会话,在该onComplete()
方法中执行了这些行:
Log.e("not open session",Session.getActiveSession().toString());
Log.e("session","not open");
它表明:
{Session state:CLOSED, token:null, appId:***************** }
怎么了?我试过没有new Session(context)
,但得到了相同的结果。我该怎么办?