尝试集成Facebook登录时未在onActivityResult中获得回调

时间:2018-11-28 18:32:35

标签: android facebook facebook-login facebook-sdk-4.0

我一直在尝试将Facebook登录名与Android集成,但发生了登录Facebook,但是在onActivityResult中没有收到回调。我已经遵循了这一点: Facebook Login CallbackManager FacebookCallback not called? 但是,我的问题仍然没有解决。这是一个代码段:

@Override
protected FragmentPresenter getFragmentPresenter() {
    return presenter;
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    View view = inflater.inflate(getLayoutId(), container, false);
    setHasOptionsMenu(true);
    view.setClickable(true);
    setupView(view);
    //FacebookSdk.sdkInitialize(FacebookSdk.getApplicationContext());
    FacebookSdk.sdkInitialize(getContext());
    callbackManager = CallbackManager.Factory.create();
    loginFacebook.setReadPermissions(Arrays.asList(EMAIL));
    loginFacebook.setFragment(this);

    loginFacebook.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            getActivity().setResult(RESULT_OK);
            getActivity().finish();
        }

        @Override
        public void onCancel() {
            getActivity().setResult(RESULT_CANCELED);
            getActivity().finish();
        }

        @Override
        public void onError(FacebookException exception) {
            //Handle Exception
        }
    });
    return view;
}

请帮助我。

0 个答案:

没有答案