我正在尝试使用最新的 FB Sdk 登录 FB。
这是我的代码
Session currentSession = Session.getActiveSession();
if (currentSession == null || currentSession.getState().isClosed()) {
Session session = new Session.Builder(v.getContext())
.setApplicationId(getResources().getString(R.string.app_Id))
.build();
Session.setActiveSession(session);
currentSession = session;
}
if (!currentSession.isOpened()) {
Session.OpenRequest openRequest = null;
openRequest = new Session.OpenRequest(FBLogin.this);
if (openRequest != null) {
openRequest.setDefaultAudience(SessionDefaultAudience.EVERYONE);
openRequest.setPermissions(PERMISSIONS);
openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
currentSession.addCallback(callback);
currentSession.openForRead(openRequest);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Constants.RESULT_OK) {
finish();
} else Session.getActiveSession().onActivityResult(this, requestCode,
resultCode, data);
}
private Session.StatusCallback callback = new Session.StatusCallback() {
public void call(Session session, SessionState state,
Exception exception) {
onSessionStateChange(session, state, exception);
}
};
private void onSessionStateChange(Session session, SessionState state,
Exception exception) {
if (state.isOpened()) {
registerWithServer(session);
} else if (state.isClosed()) {
mDialog.dismiss();
Utilities
.displayAlert(
"Oops!",
"Could not connect to Facebook. Try removing application"
+ "from App dashboard", FBLogin.this);
}
}
代码在您第一次尝试运行时运行良好。但如果应用程序被卸载或重新安装,然后您尝试登录,它会打开 FB 页面,请求权限,然后给出FacebookException
无效令牌。
我通过“尝试从应用仪表板中删除应用程序”修复它的唯一方法
到底是怎么回事?FB 代币如何运作?在重新授权时,它应该创建一个新令牌而不是失败,对吗?