简体   繁体   中英

When I try using the facebook sdk to login in my android app, I keep getting a null user and a null error. I have no clue why

I have double checked to make sure the app ids are the same. I don't know what could possibly be causing this. I can post code snippets if you would like, but I basically followed the docs on setting up Facebook with Parse.

Here is a small snippet of my code:

facebookLogInButton.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
        List<String> permissions = Arrays.asList(Permissions.User.EMAIL);
        ParseFacebookUtils.logIn(permissions, getActivity(), new LogInCallback() {
            @Override
            public void done(ParseUser user, ParseException e) {
            if (user != null) {//if user exists
                ParseUser currentUser = ParseUser.getCurrentUser();//get user
                userDisplay.setText(currentUser.getString("username"));//set username to textedit
            } else {
                userDisplay.setText(e.getMessage());//print the error
            }


            }

        });

        }

    });

Currently it crashes due to a null pointer error when trying to get the error message (in the else statement). So, not only is it failing the login process, I have a feeling that for some reason, it is not being initialized properly.

I have initialized Facebook in my application class like so:

ParseFacebookUtils.initialize(getResources().getString(R.string.facebook_app_id));

Thanks in advance.

Figured out the answer:

I had initially had the onActivityResult inside my LogInFragment.java. Instead I needed to put it inside the Activity that held the fragment.

So, put this:

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

inside the activity (NOT the fragment) where the login is happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM