2

I was using Parse with AWS hosting at first for my application but later when Parse shut down their service I moved to back4app. My Login and Signup used to work fine with the previous Parse project but now whenever I Login or Signup with my back4app project, I get the error com.parse.ParseRequest$ParseRequestException: unauthorized. I have tried using Client Key and Master Key both but they don't seem to work at all.

Here's my Signup Code:

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());

                }



            }
        });


    }

}

and here's my Login Code:

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);

                }
            }
        });
    }
}
rici
  • 234,347
  • 28
  • 237
  • 341
Hamza Amin
  • 49
  • 7

1 Answers1

0

(Just for tests) I recommend that you use the appID too to connect at Back4App! For example the code below:

<resources>

<string name="back4app_server_url">https://parseapi.back4app.com/</string>

<!-- Change the following strings as required -->
<string name="back4app_app_id">PASTE_YOUR_APPLICATION_ID_HERE</string>
<string name="back4app_client_key">PASTE_YOUR_CLIENT_KEY_HERE</string>
<string name="back4app_master_key">PASTE_YOUR_MASTER_KEY_HERE</string>
<string name="app_name">QuickstartExampleApp</string>

nataliec
  • 502
  • 4
  • 14