问题描述
您好,我正在开发 Android 应用程序,其中使用了 parse cloud.在我尝试从解析中获取数据之后,我已经注册到系统中.
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.
但我每次都遇到异常
com.parse.ParseRequest$ParseRequestException:会话令牌无效
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.
推荐答案
Googling 和 Parse 文档没有提供太多有关此异常的信息,但我发现了一些常见错误.您应该将用户视为 ParseUser
,而不是 ParseObject
.
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();
另一种情况:需要指定在后台查找什么.如果是username
,那么写:
One more case: need to specify what to find in background. If it is username
, so write:
parseQuery.whereEqualTo("username", userName);
最后回调将包含 List
和 ParseUser
s,而不是 ParseObject
s
And finally callback will contain List
with ParseUser
s, not ParseObject
s
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.
一些有用的链接:文档示例、answer, ParseQuery
类的文档和示例
Some useful links: doc with example, answer, Doc for class ParseQuery
with examples
更新
这是官方doc 如何处理这个错误,正如我所评论的,在 Parse.initialize();
之后尝试使用 ParseUser.enableRevocableSessionInBackground()
根据 SDK 文档,它会更新会话令牌,只有一种情况可能无效 - ParseObject
已删除.希望有所帮助.
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.
这篇关于com.parse.ParseRequest$ParseRequestException: 无效的会话令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!