如何解决为什么我无法从我的 Swift 代码和我的 node.js 云函数代码中获取我的 Plaid 链接令牌?
我有一个用 node.js 编写的 firebase 云函数,它是从自定义 swift 类调用的,但是当我尝试执行云函数时,我没有取回链接令牌,只是零。 这是我的云功能:
// PLAID
const plaid = require('plaid');
exports.createPlaidLinkToken = functions.https.onCall(async (data,context) => {
const customerId = context.auth.uid
const plaidClient = new plaid.Client({
clientID: functions.config().plaid.client_id,secret: functions.config().plaid.secret,env: plaid.environments.sandbox,options: {
version: '2019-05-29'
}
})
return plaidClient.createLinkToken({
user: {
client_user_id: customerId
},client_name: 'Bon Voyage',products: ['auth'],country_codes: ['US'],language: 'en'
})
.then((apiResponse) => {
const linkToken = apiResponse.link_token
return linkToken
})
.catch((err) => {
functions.logger.log(err)
throw new functions.https.HttpsError('internal','Unable to create plaid link token: ' + err)
})
})
这是我的自定义 swift 类:
class PlaidApi {
class func createLinkToken(completion: @escaping (String?) -> () ) {
Functions.functions().httpsCallable("createPlaidLinkToken").call { (result,error) in
if let error = error {
debugPrint("Got here 1: \(error.localizedDescription)")
return completion(nil)
}
guard let linkToken = result?.data as? String else { print("Got here 2"); return completion(nil) }
completion(linkToken)
}
}
}
这里是调用类函数的地方:
@IBAction func userIconClicked(_ sender: Any) {
let userActionSheet = UIAlertController(title: nil,message: nil,preferredStyle: .actionSheet)
let logOut = UIAlertAction(title: "Log Out",style: .default) { (action) in
// Logout
do {
try Auth.auth().signOut()
print("DEBUG: got here")
} catch {
print("DEBUG: \(error.localizedDescription)")
}
}
let manageCreditCards = UIAlertAction(title: "Manage Credit Cards",style: .default) { (action) in
// Display Stripe Widget
self.paymentContext.pushPaymentOptionsViewController()
}
let manageBankAccounts = UIAlertAction(title: "Manage Bank Accounts",style: .default) { (action) in
// Display Bank Accounts
PlaidApi.createLinkToken { linkToken in
print(linkToken)
}
}
let closeAlertAction = UIAlertAction(title: "Close",style: .cancel)
userActionSheet.addAction(logOut)
userActionSheet.addAction(manageCreditCards)
userActionSheet.addAction(manageBankAccounts)
userActionSheet.addAction(closeAlertAction)
present(userActionSheet,animated: true)
}
正如我所说,我只在 Xcode 调试器窗口中打印出错误消息 "Got here 1: The data couldn't be read because it isn't in the correct format." nil
。
解决方法
成功了!我在我的项目中使用了错误的 Xcode 环境。我有一个生产环境和一个开发环境。我使用的是生产环境而不是开发环境。所以我的 swift 代码试图在生产 firebase 云函数中调用一个仅存在于开发 firebase 云函数中的云函数。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。