Android Facebook SDK v3.0 SSO LoginButton returnin

2019-06-22 14:26发布

问题:

So I have a simple login button that does this in my oncreate:

 mLoginButton = (LoginButton)findViewById(R.id.connect_facebook_button);
    mLoginButton.setApplicationId(.getResources().getString(R.string.app_id));
    mLoginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        public void onUserInfoFetched(GraphUser user) {
            setUser(user); // Just sets mUser to be this user
            try {
            Toast.makeText(this, mUser.getFirstName(), Toast.LENGTH_SHORT).show();
            } catch (Exception FacebookException) {
                FacebookException.printStackTrace();
            }


        }
    });

All of that is called successfully, including the onUserInfoFetched.

The problem is, in every instance, my Graphuser user is null.

My appID is correct, my android hash is the debug one that they give me (tested on sample apps worked fine), the login screen does actually pop up... Not really sure where to go from here.

Also, if I hit the button twice, I get an error:

an attempt was made to open a session that has a pending request

回答1:

Whoops! Forgot my activity result!

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

That did the trick.