【问题标题】:Parameter in cloud function using Parse and Angular $resource使用 Parse 和 Angular $resource 的云函数中的参数
【发布时间】:2015-05-22 18:07:20
【问题描述】:

我正在尝试调用这个 [云函数]..

Parse.Cloud.define("getMyData", function(request, response) {
  console.log('request is : '+JSON.stringify(request));
  console.log('parameter is : '+request.params.name);
  //...
  response.success('Run method successfully');
});

使用来自 Angular 前端的 Parse REST api。

$resource 'https://api.parse.com/1/functions/getMyData', {},
    myCustomMethod:
      method: 'POST'
      headers:
        'X-Parse-Application-Id': 'FjV0J.....'
        'X-Parse-REST-API-Key': 'Tr7Sipvu....'
      params:
        name: 'William'

我的云函数被调用,但我似乎无法检索我的 name 参数:

I2015-05-16T00:51:08.497Z]request is : {"body":"{}","params":{},"installationId":"","user":null,"master":false}
I2015-05-16T00:51:08.497Z]parameter is : undefined

为什么我的参数没有出现在 params 中? 使用 Angular $resource 进行此类 API 调用有问题吗?

【问题讨论】:

    标签: angularjs parse-platform coffeescript


    【解决方案1】:

    让我走上正确道路的是它在使用 curl 调用时效果很好 - 正如 here 所记录的那样。

    最后,我能够使用$http 而不是$resource 来检索我的参数:

    // In controler
    $http.post 'https://api.parse.com/1/functions/getMyData'
          ,
            name: 'William'
          ,
            method: 'POST'
            headers:
              'X-Parse-Application-Id': 'FjV0J.....'
              'X-Parse-REST-API-Key': 'Tr7Sipvu....'
          .success (data) ->
            $scope.data = data
    

    Parse 似乎希望 parameters 通过 data 传输,而 Angular $resource 则无法做到这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 2015-06-22
      • 1970-01-01
      • 2016-12-17
      • 2013-07-30
      相关资源
      最近更新 更多