在我的Android应用程序中使用parse-server和heroku。想要创建后台作业,就像之前由Parse提供的那样,但似乎无法使其工作。 在parser-server-example文件夹中,我添加了一个包含以下内容的jobs.js文件:
var Parse = require('parse / node'); Parse.initialize('my_app_id'); Parse.serverURL ='random-name.herokuapp/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); } }); 函数sayHello(){ console.log('Hello'); } sayHello(); saveSomething();sayHello()运行良好,但saveSomething()运行时会得到error: heroku运行节点jobs.js。 所以我有2个问题。
1.是否正确使用parse-server& amp; amp; heroku?
2.jobs.js代码有什么问题/为了完成后台工作任务应该以不同的方式完成?
(尝试将javascript-key添加到Parse.initialize('app-id','javascript-key');没有任何运气)
解决方案解决方案是添加Parse.Cloud.useMasterKey();在Parse.serverURL =' random-name.herokuapp/parse 这行后面,然后添加parse.initialize('my_app_id','js-key','master-key')中的应用程序主密钥;获得正确的授权。
var Parse = require('parse / node'); Parse.initialize('app-id','js-key','master-key'); Parse.serverURL ='random-name.herokuapp/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 ,错误){ console.log(Fail:+ error.message); } }); } saveSomething();希望这可以帮助别人。
Using parse-server and heroku for my Android application. Want to create background jobs, like the ones offered by Parse 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 = 'random-name.herokuapp/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 = 'random-name.herokuapp/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 = 'random-name.herokuapp/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.
更多推荐
后台作业使用parse
发布评论