【发布时间】:2021-03-07 13:42:34
【问题描述】:
我正在构建一个适用于 Plaid 的应用程序。 Plaid 提供了一个不错的小 LinkKit,我需要用它来获取我的 link_token。我提供link_token 以向银行进行身份验证。当有人想要添加另一个帐户时,我已经使用 Alamofire 编写了一个请求以发送 .post 以获取新的 link_token。我的问题是,当我将 JSON 解码为我构建的结构时,我似乎无法使用存储的 link_token 值。
检索link_token的代码
let parameters = PlaidAPIKeys(client_id: K.plaidCreds.client_id,
secret: K.plaidCreds.secret,
client_name: K.plaidCreds.client_name,
language: K.plaidCreds.language,
country_codes: [K.plaidCreds.country_codes],
user: [K.plaidCreds.client_user_id: K.plaidCreds.unique_user_id],
products: [K.plaidCreds.products])
func getLinkToken() {
let linkTokenRequest = AF.request(K.plaidCreds.plaidLinkTokenURL,
method: .post,
parameters: parameters,
encoder: JSONParameterEncoder.default).responseDecodable(of: GeneratedLinkToken.self) { response in
print(response)
}
}
我构建的结构:
struct GeneratedLinkToken: Decodable {
let expiration: String
let linkToken: String
let requestID: String
enum CodingKeys: String, CodingKey {
case expiration = "expiration"
case linkToken = "link_token"
case requestID = "request_id"
}
}
我已经通过在按下我的添加帐户或虚拟按钮时调用函数getLinkToken() 进行了测试,我确实得到了我需要的数据。为什么我不能在请求后直接访问GeneratedLinkToken.linkToken?
【问题讨论】: