【问题标题】:Parse Cloud Code Error - 'Master Key is Required'?解析云代码错误 - “需要主密钥”?
【发布时间】:2017-04-13 15:45:42
【问题描述】:

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

生成响应时出错。解析错误 { 代码:141,消息:'推送失败发送错误:需要主密钥'}

我尝试过使用网站上的其他一些解决方案,例如使用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")
        }
    }
}

【问题讨论】:

  • 你是如何/从哪里运行它的?客户端存在错误
  • 我从我的 swift 应用程序中运行它。该错误出现在 Parse 仪表板日志中,并在我尝试通过我的应用程序激活它时作为错误消息返回。
  • 刚刚编辑了原始问题。对此感到抱歉。
  • 使用 Parse 已经有一段时间了,但我记得云代码应该允许您推送没有问题,而且您的错误似乎是认为您正在尝试从 swift 代码本身发送推送。
  • 您是否在 index.js 中配置了 masterKey? masterKey : process.env.MASTER_KEY ||'your masterkey'

标签: javascript swift parse-platform bitnami


【解决方案1】:

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

您是否在 index.js 中配置了 masterKey? masterKey : process.env.MASTER_KEY ||'你的主密钥'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 2013-04-17
    • 2016-05-04
    • 1970-01-01
    • 1970-01-01
    • 2013-01-21
    • 2012-12-02
    相关资源
    最近更新 更多