我正在使用 Firebase 云函数。在 iOS 设备上,我正在部署触发器以在 Node.Js 中运行云功能。在 Xcode 中——这是我触发云功能的客户端函数——我正在传递字典 data
func updateTermsOfServiceCloudCall(){
let data = [
"accountId": "acct_1Ew#######"
]
Functions.functions().httpsCallable("updateAccountWithTOA").call(data) { (result, error) in
}
现在在 Node 中,我正在运行此代码以部署到 Firebase 云
exports.updateAccountWithTOA = functions.https.onRequest((request, response) => {
const data = request.body;
const accoundId = data.accoundId;
stripe.accounts.update(
accoundId,
{
tos_acceptance: {
date: Math.floor(Date.now() / 1000),
ip: request.ip
}
},
)
});
我希望获得从我的 iOS 客户端传递过来的字典数据。但是,我在获取 Node 中的数据时遇到了问题。我以为 request.body 会给我数据,但我猜我错了,因为我收到了这个错误。任何帮助或建议将不胜感激。谢谢
Error: Stripe: Argument "id" must be a string, but got: undefined (on API request to
POST /accounts/{id}
)
最佳答案
您的客户端代码正在尝试调用 callable function ,但您的函数定义为 HTTP type function .它们是不同的东西。您无法使用 Functions SDK 调用常规 HTTP 函数。
如果要使用Functions SDK 来调用函数,则需要使用onCall 而不是onRequest 来定义它,如documentation for callable functions 所示。 .或者,如果您不想在后端调用,则需要使用 HTTP 客户端库调用常规 HTTP 函数。
关于Node.Js 从 POST 请求中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57083275/