ios - 如何在我的 iOS 应用程序中调用 Cloud Code Function(Parse)?

标签 ios xcode swift parse-platform parse-cloud-code

我不知道将哪些参数传递到此云代码函数(parse.com)

Parse.Cloud.define('stripe_card_create', function(req, res) {
Parse.Cloud.httpRequest({
method: 'POST',
headers: stripe_headers,
url: environment.stripe.api_url + '/customers/' + req.params.customer_id + '/sources',
params: {
  source: req.params.token_id
},
success: function(card) {
  res.success(card.data);
},
error: function(err) {
  res.error(err.text);
    }
  })
});

这些应该被称为

req.customer_id(必填)客户 ID

req.token_id(必填) token 化卡
但是当我使用此函数调用时收到错误

PFCloud.callFunctionInBackground("stripe_card_create", withParameters: ["req.params.customer_id":"req.params.token_id"])

这是错误

   [Error]: {
      "error": {
        "type": "invalid_request_error",
        "message": "No such customer: undefined",
        "param": "customer"
      }
    }
     (Code: 141, Version: 1.7.5)

最佳答案

在云函数中,req.params.customer_id的英文意思是这样的:

function(req, res)中的req中,获取params。从 params 属性中,获取名为 customer_id 的键。当您从 Swift 代码调用该函数时,您传递的字典键将是 params 的属性。

您的云代码需要键 customer_id,而不是 req.params.customer_id。您想要执行此操作:

PFCloud.callFunctionInBackground("stripe_card_create", withParameters: ["customer_id": "\(whatever the id is you need to pass)"], block: nil)

您在字典中传递的键值的命名也非常奇怪。要么这是一个同样的错误,要么你真的应该将其重命名为更好的名称。

关于ios - 如何在我的 iOS 应用程序中调用 Cloud Code Function(Parse)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32415413/

相关文章:

ios - 找不到“JWPlayer-iOS-SDK/JWPlayerController.h”文件

ios - Cocoapods项目设置问题

xcode - 无法将类型 'NSData' 的值转换为预期的参数类型 'String'

ios - 自定义相机 View Swift iOS 8 iPhone Xcode 6.1

ios - 使用iOS版Google Maps API无法获取当前位置坐标

ios - 从 iOS 模拟器应用打开 Finder 窗口路径

ios - 内部版本号不是由 faSTLane 设置的,而是由 Xcode 设置的

ios - 我可以在 FBFriendPickerViewController 中过滤用户列表吗?

iPhone sdk Facebook登录问题

Swift 二元运算符 '+=' 不能应用于类型为 'AnyObject!' 和 'String!' 的操作数