解析云代码功能不能使用主密钥,它没有被提供

Parse Cloud Code function Cannot use the Master Key, it has not been provided

本文关键字:主密钥 代码 功能 能不能      更新时间:2023-09-26

我在执行一个函数时遇到了一些麻烦,因为我一直得到关于我的masterKey未提供的相同错误:

[PFCloud callFunctionInBackground:@"changeUserModeratorStatus" withParameters:@{@"objectId": self.objId}];
函数:

Parse.Cloud.define("changeUserModeratorStatus", function(request, response) {
  Parse.Cloud.useMasterKey();
  var query = new Parse.Query(Parse.User);
  query.equalTo("objectId", request.params.objectId);
  query.first({
    success: function(anotherUser) {
      anotherUser.set("ModeratorStatus", "Approved");
      anotherUser.save(null, {
      success: function(anotherUser) {
        response.success("Successfully updated user.");
      },
    error: function(failedRetrieve, error) {
     response.error("Could not save changes to user.");
    }
   });
   },
   error: function(error) {
    response.error("Could not find user."); 
   }
  });
});

编辑,我已经在论坛上复制/粘贴了hector的例子,检查了文档,还没有找到解决方案。无论我做什么,我得到一个错误:不能使用主密钥,它还没有提供

您可能在初始化云代码时丢失了主密钥-

 Parse.initialize(applicationId, javaScriptKey, masterKey).

取出整个初始化为我解决了这个问题,因为Parse实际上是用application id, JavaScript keymaster key初始化你的云代码,所以你不必这样做。