JavaScript SDK 上的 Parse Push Rest API 出现 400 错误请求错误

400 Bad Request Error with Parse Push Rest API on JavaScript SDK

我的 Ionic 应用程序遇到问题。我正在尝试使用 Rest API 通过 Parse 发送推送通知。我可以使用他们的推送控制台成功发送通知。

然而,以下函数抛出错误代码 115 和一条消息,指出 "error: "缺少推送数据。”如果您需要有关该问题的任何其他信息,请告诉我。
谢谢。

$scope.send = function()


{
    $http({
      url: "https://api.parse.com/1/push",
      method: "POST",
      data: {
        "alert": "Alert Message", //not platform specific
        "badge": "1", //platform specific iOS
        "sound": "", //platform specific iOS
        "channels":["test"] 
      },
      headers: {
        "X-Parse-Application-Id": "removed",
        "X-Parse-REST-API-Key": "removed",
        "Content-Type": "application/json"
      }
      }).success(function (data, status, headers, config) {
              console.log("Push sent!");
                  //alert('iOS registered success = ' + data + ' Status ' + status); 
          }).error(function (data, status, headers, config) {
              console.log(config)
    });

  };

我想出了一个解决办法。以下适用于 REST API:

$scope.send = function()


{
    $http({
      "url": "https://api.parse.com/1/push",
      "method": "POST",
      "data": {
          "data": { "alert": "Alert Message", "sound": "", "badge": "Increment" },"channel":""
         // this line needed correct JSON formatting
      },
      "headers": {
          "X-Parse-Application-Id": "removed",
          "X-Parse-REST-API-Key": "removed",
          "Content-Type": "application/json"
      }
  }).success(function (data, status, headers, config) {
              console.log("Push sent!");
                  //alert('iOS registered success = ' + data + ' Status ' + status); 
          }).error(function (data, status, headers, config) {
              console.log(config)
    });

  };

我没有正确的 JSON 键值格式。希望这对其他人在使用 Angular 使用 Parse REST API 发出 HTTP POST 请求时有所帮助。