通过电子邮件从ParseUser获取ObjectID

时间:2015-04-19 17:11:42

标签: android parse-platform

有 我想使用Parse Query来获取objectID(不是当前用户),然后使用userID来从ParseUser获取配置文件img

 ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
        userQuery.whereEqualTo("username",name);
        userQuery.findInBackground(new FindCallback<ParseUser>() {
            public void done(List<ParseUser> results, ParseException e) {
                // results has the list of users with a hometown team with a losing record
                String testObjectID =results.get().getObjectId();
                    Log.d("score", testObjectID.toString());
            }
        });

在我上面提到的代码中,我想找到User email来获取ObjectID, 但是需要get(int position),我能做的是获取电子邮件帐户的位置来获取ObjectID吗?

String testObjectID =results.get(0).getObjectId();
从另一方面来说,也不适合我...   对象总是为空......

  ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
    query.whereEqualTo("username",name);
    Log.d("score name", name);
    query.getFirstInBackground(new GetCallback<ParseObject>() {
        public void done(ParseObject object, ParseException e) {
            if (object == null) {
                Log.d("score", "The getFirst request failed."+e.toString());
            } else {

                String testObjectID = object.getObjectId();
                Log.d("score", testObjectID.toString());
            }
        }
    });

日志

04-20 10:09:03.301  15623-15623/com.di D/memalloc﹕ ion: Unmapping buffer  base:0x52937000 size:4096
04-20 10:09:03.311  15623-15623/com.di D/score name﹕ a2@msn.com
04-20 10:09:03.321  15623-15623/com.di D/score﹕ Retrieved a2@msn.com scores
04-20 10:09:03.701  15623-15623/com.di D/score testObjectID﹕ The getFirst request failed.com.parse.ParseException: no results found for query
04-20 10:09:03.971  15623-15623/com.di D/memalloc﹕ ion: Mapped buffer base:0x577fa000 size:1536000 offset:0 fd:74
04-20 10:09:03.971  15623-15623/com.di D/memalloc﹕ ion: Mapped buffer base:0x50ae1000 size:4096 offset:0 fd:82

请帮忙,谢谢

1 个答案:

答案 0 :(得分:0)

最后,我解决了,需要在List

上使用循环
ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
userQuery.whereEqualTo("username",name);
userQuery.findInBackground(new FindCallback<ParseUser>() {
    public void done(List<ParseUser> results, ParseException e) {
        // results has the list of users with a hometown team with a losing record
        for (int j=0 ; j< results.size(); j++) {
            String testObjectID = results.get(j).getObjectId();
            Log.d("score testObjectID", testObjectID.toString());
        }
    }
});

我得到了Query方法需要&#34; _user&#34; Getting data from object Id in Parse.com