gpt4 book ai didi

ios - Firebase 云函数始终返回 Null

转载 作者:行者123 更新时间:2023-11-28 05:52:24 25 4
gpt4 key购买 nike

我正在尝试使用以下函数与 Stripe API 交互 - 它似乎工作正常,因为 key 对象已正确记录在控制台中并按预期显示。

exports.createEphemeralKey = functions.https.onCall((data,context) => {
const stripe_version = data.api_version;
const customerId = data.customer_id;
if (!stripe_version) {
throw new functions.https.HttpsError('missing-stripe-version','The stripe version has not been provided.');
}
if (customerId.length === 0) {
throw new functions.https.HttpsError('missing-customerID','The customer ID has not been provided.');
}
return stripe.ephemeralKeys.create(
{customer: customerId},
{stripe_version: stripe_version}
).then((key) => {
console.log(key);
return key;
}).catch((err) => {
console.log(err);
throw new functions.https.HttpsError('stripe-error', err);
});
});

但是,当我从我的 Swift iOS 应用程序调用此函数时,result?.data 始终为 nil。

let funcParams = ["api_version": apiVersion, "customer_id": "......"]
functions.httpsCallable("createEphemeralKey").call(funcParams) { (result, error) in
if let error = error as NSError? {
print(error)
completion(nil,error)
}
if let json = result?.data as? [String: AnyObject] {
print("success")
print(json)
completion(json, nil)
} else {
print("fail")
print(result?.data)
}
}

最佳答案

这可能是因为您没有返回“可以进行 JSON 编码的数据”(参见 doc)。以下应该有效:

....
).then((key) => {
console.log(key);
return {key: key};
})
....

关于ios - Firebase 云函数始终返回 Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52471055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com