@Override public void call(Session session, SessionState state, Exception exception) { if (session != null && session.isOpened()) { if (AccountActivity.accountImages != null && AccountActivity.accountListViewAdapter != null) { AccountActivity.accountImages[0] = R.drawable.fb_blue; AccountActivity.accountListViewAdapter.getItem(0).setItemImageId(R.drawable.fb_blue); AccountActivity.accountListViewAdapter.notifyDataSetChanged(); } SharedPreferenceUtil.put( SharedPreferenceUtil.PREF_FACEBOOK_TOKEN, session.getAccessToken()); SharedPreferenceUtil.put( SharedPreferenceUtil.PREF_FACEBOOK_EXPIRE_DATE, dateFormat.format(session.getExpirationDate())); } else { if (AccountActivity.accountImages != null && AccountActivity.accountListViewAdapter != null) { AccountActivity.accountImages[0] = R.drawable.fb_white; AccountActivity.accountListViewAdapter.getItem(0).setItemImageId(R.drawable.fb_white); AccountActivity.accountListViewAdapter.notifyDataSetChanged(); } SharedPreferenceUtil.removeValue(SharedPreferenceUtil.PREF_FACEBOOK_TOKEN); SharedPreferenceUtil.removeValue(SharedPreferenceUtil.PREF_FACEBOOK_EXPIRE_DATE); } }
/** * Gets the date at which the current session will expire or null if no session has been created. * * @return the date at which the current session will expire */ protected final Date getExpirationDate() { if (sessionTracker != null) { Session currentSession = sessionTracker.getOpenSession(); return (currentSession != null) ? currentSession.getExpirationDate() : null; } return null; }
private static void finalizeLogin( Session session, SessionState state, Exception exception, final UnityMessage unityMessage, final Activity activityToClose) { if (activityToClose != null) { activityToClose.finish(); } if (!session.isOpened() && state != SessionState.CLOSED_LOGIN_FAILED) { unityMessage.sendError("Unknown error while opening session. Check logcat for details."); return; } if (session.isOpened()) { unityMessage.put("opened", true); } else if (state == SessionState.CLOSED_LOGIN_FAILED) { unityMessage.putCancelled(); } if (session.getAccessToken() == null || session.getAccessToken().equals("")) { unityMessage.send(); return; } // there's a chance a subset of the permissions were allowed even if the login was cancelled // if the access token is there, try to get it anyways // add a callback to update the access token when it changes session.addCallback( new StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { if (session == null || session.getAccessToken() == null) { return; } final UnityMessage unityMessage = new UnityMessage("OnAccessTokenUpdate"); unityMessage.put("access_token", session.getAccessToken()); unityMessage.put( "expiration_timestamp", "" + session.getExpirationDate().getTime() / 1000); unityMessage.send(); } }); unityMessage.put("access_token", session.getAccessToken()); unityMessage.put("expiration_timestamp", "" + session.getExpirationDate().getTime() / 1000); Request.newMeRequest( session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { unityMessage.put("user_id", user.getId()); } unityMessage.send(); } }) .executeAsync(); }