When asking the user to login into my app through the Facebook login, I want to retrieve their email and name in order for them to create a custom account for our application. However, after asking them to login through Facebook and authorizing our app for the user's name and email, the app does not transition to the registration fragment and input the information into the email and name fields.
In the LoginFragment, I have this section of code dedicated to retrieving the user's email and name.
mFaceLogin = (LoginButton) v.findViewById(R.id.login_button);
mFaceLogin.setReadPermissions(Arrays.asList("email", "public_profile"));
mFaceLogin.setFragment(this);
mFaceLogin.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
final AccessToken accessToken = loginResult.getAccessToken();
GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject user, GraphResponse graphResponse) {
if (graphResponse.getError() == null) {
((MyRegisterListener) getActivity()).myStartRegisterFacebook(user.optString("first_name"), user.optString("email"));
}
}
});
}
@Override
public void onCancel() {
Toast.makeText(getActivity(), "fail", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException error) {
Toast.makeText(getActivity(), "error", Toast.LENGTH_SHORT).show();
}
});
The myStartRegisterFacebook method is suppose to make a call to the Activity to both switch to the RegisterFragment and send the name and email to the EditText fields displayed in the RegisterFragment's xml layout.
LoginActivity
@Override
public void myStartRegisterFacebook(String name, String email) {
RegisterFragment registerFragment = new RegisterFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.lr_container,
new RegisterFragment()).addToBackStack(null).commit();
registerFragment.updateInformation(name, email);
}
RegisterFragment
public void updateInformation(String name, String email) {
mFname.setText(name);
mEmail.setText(email);
}