保存用户导致找不到对象错误 [英] Saving user causes object not found error

查看:105
本文介绍了保存用户导致找不到对象错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

保存用户会导致错误:找不到要更新的对象(代码:101,版本:1.2.19)

Saving a user causes Error: object not found for update (Code: 101, Version: 1.2.19)

   [PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) {
        if (!error) {
            [PFUser currentUser].location = geoPoint;
            [[PFUser currentUser] save];
        }
    }];

我在做什么错了?

http发布请求 https://api.parse.com/2/update

http post request https://api.parse.com/2/update

{
    "iid": "[redacted]",
    "classname": "_User",
    "data": {
        "email": "test@test.com",
        "objectId": "[redacted]"
    },
    "session_token": "[redacted]",
    "v": "i1.2.19",
    "uuid": "[redacted]"
}

响应

{
    "code": 101,
    "error": "object not found for update"
}

推荐答案

我和您有相同的问题,我做了一些测试并找出了根本原因:

I have the same problem as you, I done some testing and figure out root cause:

  • 将新类GameScore创建为文档
  • 执行相同的创建和更新对象,并发现其工作正常
  • 检查"ACL"列并与您的问题数据进行比较.看到吗?


Works ACL,我对*进行了修改以使其清晰


Works ACL, I done modify for * to make it clear


ACL失败.


Failed ACL.

您可能会看到对用户"6iIv5XWZvM"的写特权锁定,这就是为什么您的更新将未找到对象"

As you could see the write privilege lock to user "6iIv5XWZvM", that's why your update will "not found object"

您可以将数据记录直接更改为"*",以使更新正常进行.

You could change data record directly to "*" to let your update works well.

好!解决方法如下:

  1. 按如下所示更改每个记录"ACL"数据列:

  1. Change every record "ACL" data col as follow:

{"*":{"write":true,"read":true}}

{"*":{"write":true,"read":true}}

您需要以特定用户身份登录PFUSer才能将ACL更改为public.就我而言,使用objectId将为"6iIv5XWZvM".我需要设置密码和登录信息,并使用代码登录和修改它.详细的iOS代码如下:

You need login PFUSer as specific user to change ACL to public. For my case use objectId will be "6iIv5XWZvM". I need set password and login info and use code to login and modify it. Detail iOS code as follow:

 //iOS Sample
 [PFUser logInWithUsernameInBackground:@"USERNAME" password:@"PASSWORD" block:^(PFUser *user, NSError *error) {
    if (user) {
        PFQuery *query = [PFQuery queryWithClassName:CLASS_NAME];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objs, NSError *error) {
            for (PFObject *obj in objs) {
                PFACL *defaultACL = [PFACL ACL];
                [defaultACL setPublicReadAccess:YES];
                [defaultACL setPublicWriteAccess:YES];
                [obj setACL:defaultACL];
                [obj saveInBackground];
            }
        }];
    } else {
        // The login failed. Check error to see why.
        }
}];

但是,如果您不想再发生任何事情,请记住在保存新数据之前添加以下设置(注意:这将是安全问题)

However remember to add following setting before you save new data, if you don't want to happen anymore (note: it will be security concern)

//It is iOS code sample.
PFACL *defaultACL = [PFACL ACL];
[defaultACL setPublicReadAccess:YES];
[defaultACL setPublicWriteAccess:YES];
[PFACL setDefaultACL:defaultACL withAccessForCurrentUser:YES];

这篇关于保存用户导致找不到对象错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆