很有可能我做错了什么,但我尝试结合the code at this page on GET requests with code to send pushes through background jobs,创建可以获取 the price of a bitcoin 的代码, 如果抓取成功,则将其作为推送发送。这是我的代码:
var query = new Parse.Query(Parse.Installation);
Parse.Cloud.job("sendAlert", function(sendAlert, status) {
Parse.Cloud.httpRequest({
url: 'https://api.bitcoinaverage.com/ticker/global/USD/last',
success: function(httpResponse) {
console.log(httpResponse.text);
Parse.Push.send({
where: query, // Set our Installation query
data: {
alert: (httpResponse.text)
}
}, {
success: function() {
status.success("Push Worked!!!");
},
error: function(error) {
status.error("Uh oh, something went wrong.")
}
});
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
}
});
注意:我似乎无法弄清楚如何在上面的 block 中正确设置格式 - 这是它在我的编辑器中的照片。
该代码的预期功能是从 this site 中提取 1 BTC 的美元价格。 ,并将其作为推送通知发送。
我确信我已经彻底屠杀了一些东西,但我的代码无法部署,并出现错误
Update failed with Could not load triggers. The error was Uncaught You must specify a key using Parse.initialize.
.那么,我该如何解决才能从纯文本 API 获取数据并将其作为推送发送?或者有更好的方法吗?谢谢!!!
最佳答案
需要在最开始指定一个key:
Parse.initialize("APPLICATION ID", "JAVASCRIPT KEY");
关于javascript - Parse.com 代码不会部署 : "Could not load triggers",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28640479/