3

我修改了 Facebook 好友选择器示例。我是第一次使用这个 facebook sdk。这是logcat。

10-15 06:43:16.189: D/Facebook-Example(26914): Exception: com.facebook.FacebookException: Session provided to a Request in un-opened state.

我已经检查了我的哈希键,但仍然会出现这个错误。

这不是任何重复的问题,因为最后一个解决方案没有帮助。

当加载朋友时该页面出现此错误。

4

1 回答 1

1

I solved this problem implementing methods for manager changes of Session. I mean after the autentication you have to wait that the session is opened. So I added UiLifecycleHelper object and the method that facebook suggests:

public class SelectionFragment extends Fragment {

private MainActivity activity;
private Context context;
private UiLifecycleHelper uiHelper;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = (MainActivity) getActivity();
    context = activity.getApplicationContext();
    uiHelper = new UiLifecycleHelper(activity, sessionCallback);
    uiHelper.onCreate(savedInstanceState);

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.selection_fragment, container, false);
    return view;
}


// Define a private variable that contains the implementation of the Session.StatusCallback listener:
private Session.StatusCallback sessionCallback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);
    }
};

@SuppressWarnings("deprecation")
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (session != null && session.isOpened()) {
        makeMeRequest(session); // my request
    } else {
                    ...
    }
}

@Override
public void onResume() {
    super.onResume();
    // For scenarios where the main activity is launched and user session is not null, the session state change notification
    // may not be triggered. Trigger it if it's open/closed.
    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, nativeDialogCallback);

}

@Override
public void onPause() {
    super.onPause();
    uiHelper.onPause();
}

@Override
public void onDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
    activity = null;

}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}
}
于 2014-01-15T16:40:32.010 回答