I have got my Parse stuff running on Back4App. I have gotten Facebook signup/login working that goes through Parse and authenticates with Facebook, if the user doesn't exist in the Parse user table it creates the entry. User can then login/logout on the Android app fine, all working.
The problem I'm having is Parse is not saving the username/email it first retrieved from Facebook, it's saving a session token in the username field (or some other value I'm unsure of). I want it to save the user's email and name retrieved from Facebook in the _User table.
I can see when I trace the code in Android Studio it can see my full name, email, etc pulled from Facebook but it's not putting that info into the Parse _User table.
eg when I signup to the app using my facebook account:
@Override
public void onClick(View v) {
ParseFacebookUtils.logInWithReadPermissionsInBackground(Login.this, permissions, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException err) {
if (user == null) {
Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew()) {
Log.d("MyApp", "User signed up and logged in through Facebook!");
getUserDetailFromFB();
Intent intent = new Intent(getApplicationContext(),CategoryList.class);
startActivity(intent);
finish();
} else {
Log.d("MyApp", "User logged in through Facebook!");
getUserDetailFromParse();
Intent intent = new Intent(getApplicationContext(),CategoryList.class);
startActivity(intent);
finish();
}
}
});
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
}
void getUserDetailFromParse(){
ParseUser user = ParseUser.getCurrentUser();
mUsernameField.setText(user.getUsername());
mUsernameField.setText(user.getEmail());
Toast.makeText(getApplicationContext(), "Welcome Back!" + mUsernameField.getText().toString() + " Login.Email:" + mUsernameField.getText().toString(), Toast.LENGTH_SHORT).show();
}
void getUserDetailFromFB(){
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),new GraphRequest.GraphJSONObjectCallback(){
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
try{
FbUsername=(object.getString("name"));
//FbUsername=response.getJSONObject().getString("name");
}catch(JSONException e){
e.printStackTrace();
}
try{
FbEmail=response.getJSONObject().getString("email");
}catch(JSONException e){
e.printStackTrace();
}
saveNewUser();
}
});
Bundle parameters = new Bundle();
parameters.putString("fields","name,email");
request.setParameters(parameters);
request.executeAsync();
}
void saveNewUser(){
ParseUser user = ParseUser.getCurrentUser();
user.setUsername(FbUsername);
user.setEmail(FbEmail);
//user.put("email", FbEmail);
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
Toast.makeText(getApplicationContext(), "Welcome " +FbUsername+"!", Toast.LENGTH_SHORT).show();
}
});
}