Android- 解析数据库编辑其他用户信息

Android- Parse Database edit other users' information

我正在做一个学校项目,该项目是 android 上的交通应用程序。 我正在尝试编辑另一个登录用户的用户信息。当我尝试编辑另一个用户的已保存变量时,我得到

java.lang.IllegalArgumentException: Cannot save a ParseUser that is not authenticated.

在我的搜索中,我看到有人建议将 ACL 更改为 public write on the users 以编辑它们,我试过了,不幸的是,它没有改变任何东西,我仍然有这个错误。另一个建议是使用云代码或主密钥,但我找不到任何说明如何实施它们的文档。如果有人帮助我,我会很高兴。非常感谢。

您可以像这样在云代码中使用 masterKey:

otherUser.save(null,{useMasterKey:true});

这是一个使用云代码和主密钥的完整示例:

Parse.Cloud.define("saveOtherUser", async (request) => {

  const otherUserID = request.params.otherUserID;//other user's ID;

  const user = request.user; //This is you. We are NOT gonna update this.
  //you can check your security with using this user. For example:

  if(!user.get("admin")){

    //we are checking if th requesting user has admin privaleges.
    //Otherwise everyone who call this cloud code can change other users information.

    throw "this operation requires admin privilages"

    //and our cloud code terminates here. Below codes never run
    //so other users information stays safe.
  }

  //We create other user
  const otherUser = new Parse.User({id:otherUserID});

  //Change variables
  otherUser.set("variable","New Variable, New Value");

  //Now we are going to save user
  await otherUser.save(null,{useMasterKey:true});

  //this is the response our android app will recieve
  return true;


});

这是我们 android 应用的 Java 代码:

HashMap<String, Object> params = new HashMap<>();
params.put("otherUserID", otherUser.getObjectId());

ParseCloud.callFunctionInBackground("saveOtherUser", params, new FunctionCallback<Boolean>() {
    @Override
    public void done(Boolean object, ParseException e) {
        if(e==null&&object){
            //save operation successful
        }
        else{
            //save operation failed
        }
    }
});

Aklına takılan olursa sor :)