javascript - firebase 函数将整数转换为对象
问题描述
iOS 客户端调用函数,参数如下:
func buyTicket(contestId: String, points: Int) -> SignalProducer<Void, Error> {
Functions.functions().httpsCallable("myFunction").call([
"userId": Auth.auth().currentUser!.uid,
"points": points,
"contestId": contestId
], completion: ...
然后在函数的开头我有这个日志
const userId = req.body.data.userId;
const contestId = req.body.data.contestId;
const points = req.body.data.points;
console.log(`myFunction called with userId: ${userId} contestId: ${contestId} points: ${points}`);
打印出来的是
使用 userId 调用的 myFunction:BzoW5pWLbWRnd2UgjnTkfd3xfNf2 竞赛Id:pBsQo0FHMyu4ay18dexy 点:[object Object]
为什么点转换为对象?当我尝试将点传递给时,这导致我的函数崩溃FieldValue.increment
解决方案
看起来您将HTTP Cloud Function实现与Callable Cloud Function的调用混合在一起。这两类功能不一样,也不兼容。
要从您的应用程序调用HTTP 函数,您将从 Swift 代码执行常规 HTTP 请求。例如,如何在 Swift 中发出 HTTP 请求?
如果你想让你的 Swift 代码保持不变,你必须将你的服务器端实现为 Callable Cloud Function。这意味着声明看起来像:
exports.myFunction = functions.https.onCall((data, context) => {
...
});
你得到的参数为data.userId
,data.points
等。
推荐阅读
- r - Semicontinuous data with structural and sampling (true and false) zeros
- python - 避免 seaborn 影响 matplotlib 图
- python - from bs4 import Beautifulsoup ImportError: cannot import name 'Beautifulsoup'
- ruby-on-rails - How to implement common search in mongo id when using dynamic attributes in Rails
- gradle - Replace file content in Kotlin DSL
- python - Python evdev 找不到设备
- angular - Cannot connect to AngularFireDatabase
- angular - npm install 不断删除包
- php - 离子订阅返回“错误”但 php 响应是“成功”
- java - 匿名新的 ExpectedCondition
() 可以用 lambda 代替,Java11