我想使用pushwoosh Remote API从我的Parse服务器(云代码)发送推送通知。我正在尝试关注他们的Guidelines Here,但我可以获得400错误代码以回复请求,这意味着我的请求字符串格式错误。
400 | N / A |格式错误的请求字符串(来自status codes here)
Parse.Cloud.afterSave("LinkPost", function(request, response) {
Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://cp.pushwoosh.com/json/1.3/createMessage',
data: JSON.stringify({
"request": {
"application": "APPLICATION_ID",
"auth": "AUTH_TOKEN",
"notifications": [{
"send_date": "now",
"ignore_user_timezone": true,
"content": "Hello world!"
}]
}
}),
dataType: 'json'
}).then(function(httpResponse) {
console.log(httpResponse.text);
}, function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
});
});
答案 0 :(得分:0)
首先, 永远不会 在公开场合发布您的身份验证令牌或应用ID。我强烈建议您编辑帖子并从中删除应用程序ID和身份验证令牌。
现在问题:
Parse.Cloud.httpRequest需要" body"作为参数而不是"数据"在pushwoosh $ ajax post call的指导下
Parse.Cloud.afterSave("LinkPost", function(request, response) {
Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://cp.pushwoosh.com/json/1.3/createMessage',
body: JSON.stringify({
"request": {
"application": "APPLICATION_ID",
"auth": "AUTH_KEY",
"notifications": [{
"send_date": "now",
"ignore_user_timezone": true,
"content": "Hello world!"
}]
}
}),
dataType: 'json'
}).then(function(httpResponse) {
console.log(httpResponse.text);
}, function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
});
});