Parse.com getting data from callback URL

泪湿孤枕 提交于 2019-12-12 06:58:34

问题


I'm currently trying to use an API and for the API, the developer console of that app asks the developer to submit a callback URL. Whenever the user of the app does something, it submits a GET request to the callback URL and I can retrieve data from that request. The current url I am using is https://appId:javascript-key=myJavascriptKey@api.parse.com/1/functions/receiveInfo. How can I handle the data, a.k.a the GET parameters, from the GET request? I found an answer on Parse.com that says how to retrieve data from a POST request, but all it says is that data = request.body. Do I do the same for GET requests and if so what do I do after that? Is request.body a json value?

Parse.Cloud.define("receiveInfo", function(request,response){

        var params = request.body;//is this right to get the GET parameters they send? if so what do I do next?

    });

回答1:


The documentation has your solution at: https://parse.com/docs/cloud_code_guide#functions

For GET requests you have to use the request.params object which has all your request parameters for a GET are there. POSTS are sent in the request body, GET in the request parameters.

It looks like you are trying to get the params you can use something similar to:

Parse.Cloud.define("myMethod", function(request, response) {
  if(request.params.myparam == "moo") {
    response.success("Cow!");
  }
  else {
    response.error("Unknown type of animal");
  }
});


来源:https://stackoverflow.com/questions/26644003/parse-com-getting-data-from-callback-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!