用于Android的Facebook SDK始终返回会话状态已创建

时间:2014-05-29 12:29:01

标签: android facebook session

在我的应用程序中,我有facebook登录,它完美地工作到昨天,但今天当我测试它返回会话状态Created.i已尝试多次在不同的设备但相同的response.my onCreate Code是 -

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(getActivity(), callback);
    uiHelper.onCreate(savedInstanceState);
}

我片段的onCreateView代码是 -

authButton = (LoginButton) view.findViewById(R.id.authButton);
    authButton.setFragment(this);
    authButton.setReadPermissions(Arrays.asList("basic_info","email"));


@SuppressWarnings("deprecation")
private void onSessionStateChange(final Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
            accessToken = session.getAccessToken();
            accessExpir = session.getExpirationDate();

            if (state.isOpened()) {
                if(mDialog==null){
                    mDialog = new ProgressDialog(getActivity());
                }
                if(!mDialog.isShowing()){
                    mDialog.setMessage("please wait...");
                    mDialog.setCancelable(false);
                    mDialog.show();
                }
                 Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
                     public void onCompleted(GraphUser user, Response response) {
                          session.close();
                          getUserFacebookData(user);
                     }
                 });
             }
    }else if(state.equals(SessionState.CLOSED_LOGIN_FAILED)){
    }
    else if (state.isClosed()) {
    }
}

private Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);
    }
};

@Override
public void onResume() {
    super.onResume();
    Session session = Session.getActiveSession();
    if(session != null &&
           (session.isOpened() || session.isClosed()) ) {
        onSessionStateChange(session, session.getState(), null);
    }
    uiHelper.onResume();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);
}

调用onResume()方法,然后显示会话状态 -

{Session state:CREATED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[]}, appId:**************}

任何人都可以帮助我,我已经花了一整天的时间。 提前致谢

1 个答案:

答案 0 :(得分:0)

花了很多时间为我自己的问题找到解决方案并分享它 -

在onResume()中为我添加了几行代码 -

Session s = new Session(context);
        Session.setActiveSession(s);
        s.openForRead(new Session.OpenRequest(this).setCallback(callback).setPermissions(Arrays.asList("basic_info","email")));