2

Hello I am working on android app in which I am using parse cloud. I have signUp into the system then after I am trying to fetch data from parse.

But I am getting an exception everytime

com.parse.ParseRequest$ParseRequestException: invalid session token

String userName = ParseUser.getCurrentUser().getUsername();
ParseQuery<ParseObject> parseQuery = ParseQuery.getQuery("users");
parseQuery.findInBackground(new FindCallback<ParseObject>() {

    @Override
    public void done(List<ParseObject> list, ParseException parseException) {

    }
});

How we can resolve this problem.

3 Answers 3

3

Googling and Parse docs didn't give too much info about this exception, but There are few common mistakes I found. You should treat users as ParseUser, not ParseObject.

ParseQuery<ParseUser> query = ParseUser.getQuery();

One more case: need to specify what to find in background. If it is username, so write:

parseQuery.whereEqualTo("username", userName);

And finally callback will contain List with ParseUsers, not ParseObjects

query.findInBackground(new FindCallback<ParseUser>() {
  public void done(List<ParseUser> objects, ParseException e) {
  }
});

I'm not sure exception will be gone, but I hope this answer will be useful anyways.

Some useful links: doc with example, answer, Doc for class ParseQuery with examples

UPDATE

This is the official doc how to handle this error, also as I commented try to use ParseUser.enableRevocableSessionInBackground() after Parse.initialize(); According to the SDK Documentation it is gonna update session token and only one case it could be invalid - ParseObject was removed. Hope that helps.

Sign up to request clarification or add additional context in comments.

4 Comments

where to specify class name there ?
Ah, I understood your question a little wrong, so you did right, just need to specify parseQuery. whereEqualsTo("Field name in object", NameToSearch); before you call findInBackground.
I don't want to add where clause condition.
Found one method to update session token, ty to add this line ParseUser.enableRevocableSessionInBackground() after Parse.initialize();
1

I got this error when I was trying to login while I already logged in. Try to call ParseUser.logout()

Comments

-1

As Yurets said, you probably removed the session object. This can be solved quickly by uninstalling the app and then re-installing it.

5 Comments

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. - From Review
@gio Why is it not an attempt to answer the question?
@gio I believe it does answer the question, as I've provided another approach to solving it (re-installing) which worked for me and didn't appear in the answer above.
it is solution only during developing process, but is not, for example, for app which was already published and have a lot of users
@gio fair enough. although the problem mainly occurs during development, in this case in particular.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.