During facebook login results are never returned

217 views Asked by At

I am having some problem with simple app using Facebook Login. I've checked official tutorial and some other materials but still I am unable to get the result. The problem is that onActivityResult method is called, but callback methods aren't. For me everything looks ok, so I guess I have to be missing something. This is my fragment's code:

public class MainActivityFragment extends Fragment {

    private CallbackManager callbackManager;

    public MainActivityFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
        callbackManager = CallbackManager.Factory.create();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_main, container, false);
        final LoginButton loginButton = (LoginButton)view.findViewById(R.id.login_button);
        loginButton.setReadPermissions("public_profile");
        loginButton.setFragment(this);
        loginButton.registerCallback(callbackManager, facebookCallback);
        return view;
    }

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

    private FacebookCallback<LoginResult> facebookCallback = new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            AccessToken accessToken = loginResult.getAccessToken();
            Profile profile = Profile.getCurrentProfile();
            if(profile != null) {
                Log.d("TAG","Welcome: " + profile.getName());
            } else {
                Log.d("TAG","Null?");
            }
        }

        @Override
        public void onCancel() {
            Log.d("TAG", "Cancel");
        }

        @Override
        public void onError(FacebookException e) {
            Log.d("TAG", "Error: " + e);
        }
    };
}

In my main activity I have only code generated by Android Studio and in Manifest I have everything required by Facebook SDK. Hash code and package name looks correct.

1

There are 1 answers

0
Gokhan Caglar On BEST ANSWER

Here's your problem:

callbackManager.onActivityResult(resultCode, requestCode, data);

It should be:

callbackManager.onActivityResult(requestCode, resultCode, data);