Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Parse "invalid session token" error

I am new to android and I am stuck on what seems to be a simple problem to fix but I just don't know what I am doing wrong! All I need to do is sign up a user, for some reason the e is never equal to null and therefore it goes straight to the else part which gives me the invalid session token message. Here is the code for the signup part, I looked at it thousands of times!:

protected EditText mUsername;
protected EditText mPassword;
protected EditText mEmail;
protected Button mSignUpButton;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_up_manager);

    mUsername = (EditText)findViewById(R.id.usernameField);
    mPassword = (EditText)findViewById(R.id.passwordField);
    mEmail = (EditText)findViewById(R.id.emailField);
    mSignUpButton = (Button)findViewById(R.id.signupButton);

    mSignUpButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String username = mUsername.getText().toString();
            String password = mPassword.getText().toString();
            String email = mEmail.getText().toString();

            //trims the spaces
            username = username.trim();
            password = password.trim();
            email = email.trim();

            //if one of the text edits is empty send them a message with a                                    title with an ok button.
            if(username.isEmpty() || password.isEmpty() || email.isEmpty()){
                AlertDialog.Builder builder = new AlertDialog.Builder(SignUpManagerActivity.this);
                builder.setMessage(R.string.signup_error_message)
                        .setTitle(R.string.signup_error_title)
                        .setPositiveButton(android.R.string.ok, null);

                AlertDialog dialog = builder.create();
                dialog.show();
            }
            else {
                setProgressBarIndeterminateVisibility(true);//the progress circle is active.

                //creating a new parse user.
                ParseUser pUser = new ParseUser();
                pUser.setUsername(username);
                pUser.setPassword(password);
                pUser.setEmail(email);

                pUser.signUpInBackground(new SignUpCallback() {
                    @Override
                    public void done(ParseException e) {
                        setProgressBarIndeterminateVisibility(false);//the progress circle is not active.
                        if (e == null) {
                            Intent intent = new Intent(SignUpManagerActivity.this, LoginManagerActivity.class);
                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                        } else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(SignUpManagerActivity.this);
                            builder.setMessage(e.getMessage())
                                    .setTitle(R.string.signup_error_title)
                                    .setPositiveButton(android.R.string.ok, null);

                            AlertDialog dialog = builder.create();
                            dialog.show();
                        }
                    }
                });

            }
        }
    });



}

Please help, thanks in advance!

like image 764
user5125506 Avatar asked Jan 07 '23 23:01

user5125506


1 Answers

First post here but I had the same error. Correct me if I am wrong but I believe the issue also for me was that I could create the user once and then get invalid session tokens afterwards. I think its due to the fact that the "session" on the Parse Website's end is still logged in even though you can close and re-run the app on your end.

By putting the following code before I try to create a new parse user I fixed my issue.

ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.logOut();

Hope that helps. Cheers!

like image 137
Daniel Pedroza Avatar answered Feb 02 '23 17:02

Daniel Pedroza