Using parse-server and heroku for my Android application. Want to create background jobs, like the ones offered by Parse.com earlier, but can't seem to make it work. In the parser-server-example folder, I have added a jobs.js file containing this:
var Parse = require('parse/node');
Parse.initialize('my_app_id');
Parse.serverURL = 'https://random-name.herokuapp.com/parse';
function saveSomething(){
var obj = new Parse.Object('my_class', 'random');
obj.save(null, {
success: function(place){
console.log("Success!!");
},
error: function(place, error){
console.log("Fail: " + error.message);
}
});
}
function sayHello() {
console.log('Hello');
}
sayHello();
saveSomething();
sayHello() runs fine, but saveSomething() get "error: unauthorized" message when i run: heroku run node jobs.js . So I have 2 questions.
1.Is this det correct way to create a background job using parse-server & heroku?
2.Anything wrong with the "jobs.js" code/something that should be done differently in general to accomplish the background job task?
(Tried adding javascript-key to the Parse.initialize('app-id', 'javascript-key'); without any luck)
The solutions was to add "Parse.Cloud.useMasterKey();" after the line "Parse.serverURL = 'https://random-name.herokuapp.com/parse', and add the apps master key in the "Parse.initialize('my_app_id', 'js-key', 'master-key'); to get the correct authorisation.
var Parse = require('parse/node');
Parse.initialize('app-id', 'js-key','master-key');
Parse.serverURL = 'https://random-name.herokuapp.com/parse/';
Parse.Cloud.useMasterKey();
function saveSomething(){
var MyClass = Parse.Object.extend("MyClass");
var myclass = new MyClass();
myclass.set("columnName", "value");
myclass.save({
success: function(place){
console.log("Success!!");
},
error: function(place, error){
console.log("Fail: " + error.message);
}
});
}
saveSomething();
Hope this helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With