Parse.com getting data from callback URL

2019-09-05 00:19发布

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条回答
男人必须洒脱
2楼-- · 2019-09-05 00:59

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");
  }
});
查看更多
登录 后发表回答