我最初在我的应用程序中使用带有 AWS 托管的 Parse,但后来当 Parse 关闭他们的服务时,我转向了 back4app。我的登录和注册曾经在以前的 Parse 项目中正常工作,但现在每当我使用我的 back4app 项目登录或注册时,我都会收到错误com.parse.ParseRequest$ParseRequestException: 未授权。我尝试过同时使用客户端密钥和主密钥,但它们似乎根本不起作用。
这是我的注册码:
public void clickSignup(View view) {
ParseUser.logOut();
loader = (ProgressBar) findViewById(R.id.loadingBar);
loader.setVisibility(View.VISIBLE);
ParseQuery checkAvailability = ParseUser.getQuery();
textUser = (EditText) findViewById(R.id.textUser);
textPass = (EditText) findViewById(R.id.textPass);
if (textUser.getText().toString().isEmpty() || textPass.getText().toString().isEmpty()) {
loader.setVisibility(View.INVISIBLE);
Toaster("Enter a valid username/password");
} else if (textUser.getText().length() < 4){
Toaster("Username must have four or more characters");
loader.setVisibility(View.INVISIBLE);
} else if (textPass.getText().length() < 6) {
Toaster("Password mush have atleast six or more characters");
loader.setVisibility(View.INVISIBLE);
}else{
String user = textUser.getText().toString();
Log.i("user", user);
checkAvailability.whereEqualTo("username" , user);
checkAvailability.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> objects, ParseException e) {
if (e == null && objects.size() == 1){
loader.setVisibility(View.INVISIBLE);
Toaster("This username already exists");
} else if (e == null && objects.size() != 1){
loader.setVisibility(View.INVISIBLE);
ParseUser newUser = new ParseUser();
newUser.setUsername(textUser.getText().toString());
newUser.setPassword(textPass.getText().toString());
newUser.signUpInBackground(new SignUpCallback() {
@Override
public void done(ParseException e) {
Log.i("S", "Seucbbkw");
Log.i("e", e.toString());
if (e == null){
Intent intent = new Intent(getApplicationContext(), LoggedIn.class);
intent.putExtra("Username",textUser.getText().toString() );
startActivity(intent);
Toaster("Signup Successful");
}
}
});
} else {
Log.i("Objects", e.toString());
}
}
});
}
}
这是我的登录代码:
public void clickSignin(View view){
ParseUser.logOut();
textUser = (EditText) findViewById(R.id.textUser);
textPass = (EditText) findViewById(R.id.textPass);
loader.setVisibility(View.VISIBLE);
if (textUser.getText().toString().isEmpty() || textPass.getText().toString().isEmpty()) {
loader.setVisibility(View.INVISIBLE);
Toaster("Enter a valid username/password");
} else {
final ParseQuery logInner = ParseUser.getQuery();
logInner.whereEqualTo("username", textUser.getText().toString());
ParseUser.logInInBackground(textUser.getText().toString(), textPass.getText().toString(), new LogInCallback() {
@Override
public void done(ParseUser user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getApplicationContext(), LoggedIn.class);
intent.putExtra("Username",textUser.getText().toString() );
startActivity(intent);
Toaster("Login Successful");
loader.setVisibility(View.INVISIBLE);
} else {
Toaster("Invalid username or password");
Log.i("Error", e.toString());
loader.setVisibility(View.INVISIBLE);
}
}
});
}
}