最新の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 トークンの仕組み 再承認すると、失敗するのではなく、新しいトークンを作成する必要がありますか?