You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native调用Plaid兑换public_token时无法正确提取access_token

问题修复方案

你的代码存在两处核心错误导致无法正确提取access_token:

  • 你通过response.json()拿到的返回值就是Plaid接口返回的完整JSON对象,不存在content属性,打印response.content只会返回undefined,无法看到真实返回内容
  • 你没有从返回的response对象中提取access_token字段,直接使用了未声明的access_token变量,自然无法正确赋值
修正后代码
// 调用Plaid公开令牌兑换接口:将PublicToken转换为AccessToken
fetch("https://sandbox.plaid.com/item/public_token/exchange", {
  method: "POST",
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "client_id": "[ClientID]",
    "secret": "[SandboxSecretID]",
    "public_token": success.publicToken
  }),
})
.then(response => response.json())
.then(response => {
  // 打印完整返回结果方便调试
  console.log("Plaid接口返回内容:", response);
  // 从返回结果中提取access_token
  const accessToken = response.access_token;
  setVariable({ key: 'AccessToken', value: accessToken })
})
.catch(err => {
  console.log("接口调用异常:", err);
});
调试说明

如果运行后仍然拿不到值,直接查看控制台打印的完整返回内容即可定位问题:如果返回内容包含错误提示,大概率是你的client_id、secret或者public_token参数填写错误,按照错误提示修正参数即可。

内容的提问来源于stack exchange,提问作者emig

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 23:15:09