Android Facebook用户到Parse.com
我如何从Facebook用户那里获取数据以解析.com?我将在下面提供的代码创建一个用户,但在我登录时它不会用数据更新它,为什么它不工作Android Facebook用户到Parse.com,android,facebook,parse-platform,facebook-login,Android,Facebook,Parse Platform,Facebook Login,我如何从Facebook用户那里获取数据以解析.com?我将在下面提供的代码创建一个用户,但在我登录时它不会用数据更新它,为什么它不工作 public class LoginActivity extends Activity { private EditText usernameView; private EditText passwordView; @Override public void onCreate(Bundle savedInstanceState) { super
public class LoginActivity extends Activity {
private EditText usernameView;
private EditText passwordView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
LoginButton loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onLoginButtonClicked();
}
});
// Set up the login form.
usernameView = (EditText) findViewById(R.id.etUsername);
passwordView = (EditText) findViewById(R.id.etPassword);
// Set up the submit button click handler
findViewById(R.id.ibLogin).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
onNormalLoginButton();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
}
private void onNormalLoginButton(){
// Validate the log in data
boolean validationError = false;
StringBuilder validationErrorMessage =
new StringBuilder(getResources().getString(R.string.error_intro)); //please
if (isEmpty(usernameView)) {
validationError = true;
validationErrorMessage.append(getResources().getString(R.string.error_blank_username));//enter username
}
if (isEmpty(passwordView)) {
if (validationError) {
validationErrorMessage.append(getResources().getString(R.string.error_join));// and
}
validationError = true;
validationErrorMessage.append(getResources().getString(R.string.error_blank_password));//enter password
}
validationErrorMessage.append(getResources().getString(R.string.error_end));// .
// If there is a validation error, display the error
if (validationError) {
Toast.makeText(LoginActivity.this, validationErrorMessage.toString(), Toast.LENGTH_LONG) //LENGHT_LONG means how long the message will stand
.show();
return;
}
// Set up a progress dialog
final ProgressDialog dlg = new ProgressDialog(LoginActivity.this);
dlg.setTitle("Please wait.");
dlg.setMessage("Logging in. Please wait.");
dlg.show();
// Call the Parse login method
ParseUser.logInInBackground(usernameView.getText().toString(), passwordView.getText()
.toString(), new LogInCallback() {
public void done(ParseUser user, ParseException e) {
dlg.dismiss();
if (e != null) {
// Show the error message
Toast.makeText(LoginActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
} else {
// Start an intent for the dispatch activity
ParseUser userguy=ParseUser.getCurrentUser();
boolean validated=userguy.getBoolean("emailVerified");
if(validated)
{
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("user", userguy.getObjectId());
installation.put("fullname",userguy.getString("fullname"));
installation.saveInBackground();
openMainActivity();
}else{
Toast.makeText(LoginActivity.this, "You need to confirm your Email!",Toast.LENGTH_LONG).show();
}
}
}
});
}
private void onLoginButtonClicked() {
List<String> permissions = Arrays.asList("email", "user_about_me");
ParseFacebookUtils.logInWithReadPermissionsInBackground(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()) {
Profile profile = Profile.getCurrentProfile();
user.put("gender", "");
user.put("location", "");
user.put("age", "");
user.put("meet", "");
user.put("status", "");
user.put("link", "");
user.put("fullname", profile.getName());
user.setEmail("");
user.signUpInBackground();
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("user", user.getObjectId());
installation.put("fullname", user.getString("fullname"));
installation.saveInBackground();
openMainActivity();
} else {
Log.d("MyApp", "User logged in through Facebook!");
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("user", user.getObjectId());
installation.put("fullname", user.getString("fullname"));
installation.saveInBackground();
openMainActivity();
}
}
});
}
private void openMainActivity(){
Intent intent = new Intent(LoginActivity.this, DispatchActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
private boolean isEmpty(EditText etText) {
if (etText.getText().toString().trim().length() > 0) {
return false;
} else {
return true;
}
}
public void signUp(View view) {
Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
请看下面的代码。为什么要调用user.signUpInBackground();再一次? 我认为应该是user.saveInBackground()强> 另外,请检查字段的数据类型,确保输入正确的数据类型(例如:int/float/double表示数字)
else if(user.isNew()){
Profile Profile=Profile.getCurrentProfile();
user.put(“性别”,”);
user.put(“位置”,“位置”);
user.put(“年龄”,”);
user.put(“满足”、“满足”);
user.put(“status”,”);
user.put(“link”,”);
user.put(“fullname”,profile.getName());
user.setEmail(“”);
user.signUpInBackground();
ParseInstallation=ParseInstallation.getCurrentInstallation();
installation.put(“user”,user.getObjectId());
installation.put(“全名”,user.getString(“全名”);
安装。saveInBackground();
openmain活动();
}
是的,我刚试过,但没有成功。我试着这样做,看看它是否过渡到下一个活动太快了,所以没有时间更新或做其他事情。但事实似乎并非如此。你有什么例外?让我们看看。
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if(e!=null){
Toast.makeText(LoginActivity.this,"User data didn't save!",Toast.LENGTH_SHORT).show();
}else{
openMainActivity();}
}
});