解析云代码错误 - 'Master Key is Required'?

Parse Cloud Code Error - 'Master Key is Required'?

每当我尝试 运行 这段云代码时,我都会收到一条错误消息:

生成响应时出错。解析错误 { 代码:141,消息:'Push failed to send with error: master key is required'}

我尝试遵循网站上的其他一些解决方案,例如使用 Parse.Cloud.useMasterKey()useMasterKey: true,但我没有找到任何这些命令的成功(可能是由于我使用不正确?)。

Parse.Cloud.define("sendPushToUser", function(request, response) {

    var senderUser = request.user;
    var recipientUserId = request.params.recipientId;
    var message = request.params.message;

    var recipientUser = new Parse.User();
    recipientUser.id = recipientUserId;
    var pushQuery = new Parse.Query(Parse.Installation);
    pushQuery.equalTo("user", recipientUser);

    Parse.Push.send({
            where: pushQuery,
            data: {
                    alert: message
            }
    }).then(function() {
            response.success("Push was sent successfully.")
    }, function(error) {
            response.error("Push failed to send with error: " + error.message);
    });
});

Swift函数:

func testPush() {



    PFCloud.callFunction(inBackground: "sendPushToUser", withParameters: ["recipientId": PFUser.current()?.objectId!, "message" : "Test notification"]) { (success, error) in
        if error != nil {
            print("error occurred")
        }else {
            print("Sent successfully")
        }
    }
}

正如盖勒特·李所建议的那样

您是否在 index.js 中配置了 masterKey?万能钥匙:process.env.MASTER_KEY ||'your masterkey'