的時候,這裏是我的更新狀態代碼:Facebook的會話關閉後得到嘗試後狀態
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)
,但得到相同的結果。我該怎麼辦?
你會在代碼中的任何地方關閉會話嗎? newMeRequest是異步執行的,因此會話可能在其他地方關閉。如果沒有,請發佈更完整的代碼,這個示例不足以顯示問題。 –
是的,我已經關閉了會議。但在關閉會話之前,我已將文件中的打開會話保存起來,然後我嘗試使用已保存的會話設置活動會話。如果我的過程是錯誤的,是否有其他選項發送請求與我保存的會話? @MingLi – Shoshi
不要保存會話,也不要重複使用封閉會話,只需創建一個新會話。創建起來很便宜,如果用戶已經授權應用程序(您可以檢查,因爲會話將處於CREATED_TOKEN_LOADED狀態),那麼您可以在沒有任何用戶交互的情況下打開它。 –