通过Curl/PHP从Plaid获取Access Token时遇products参数问题
Plaid Link Token创建时的products参数问题
我正尝试通过Curl/PHP从Plaid获取Access Token,调用link/token/create接口时遇到了products参数相关的一系列问题,具体如下:
尝试1:使用["balance"]作为products参数
代码:
$client_id = getenv("PLAID_CLIENT_ID"); $secret = getenv("PLAID_CLIENT_SECRET"); $data = array(); $data["client_id"] = $client_id; $data["secret"] = $secret; $data["user"] = array( "client_user_id" => '1' ); $data["products"] = ["balance"]; $data["client_name"] = 'Client Name'; $data["country_codes"] = ["US"]; $data["language"] = 'en'; $endpoint = "https://production.plaid.com/link/token/create"; $data = json_encode($data); $ch = curl_init($endpoint); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 45); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $raw_result = curl_exec($ch);
收到错误:
"provided product is not supported as an initial product: balance"
尝试2:使用["auth"]作为products参数
修改后的代码:
$client_id = getenv("PLAID_CLIENT_ID"); $secret = getenv("PLAID_CLIENT_SECRET"); $data = array(); $data["client_id"] = $client_id; $data["secret"] = $secret; $data["user"] = array( "client_user_id" => '1' ); $data["products"] = ["auth"]; $data["client_name"] = 'Client Name'; $data["country_codes"] = ["US"]; $data["language"] = 'en'; $endpoint = "https://production.plaid.com/link/token/create"; $data = json_encode($data); $ch = curl_init($endpoint); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 45); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $raw_result = curl_exec($ch); $result_array = json_decode($raw_result);
收到错误:
"client is not authorized to access the following products: ["auth"]"
尝试3:使用空数组作为products参数
代码:
$client_id = getenv("PLAID_CLIENT_ID"); $secret = getenv("PLAID_CLIENT_SECRET"); $data = array(); $data["client_id"] = $client_id; $data["secret"] = $secret; $data["user"] = array( "client_user_id" => '1' ); $data["products"] = []; $data["client_name"] = 'Client Name'; $data["country_codes"] = ["US"]; $data["language"] = 'en'; $endpoint = "https://production.plaid.com/link/token/create"; $data = json_encode($data); $ch = curl_init($endpoint); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 45); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $raw_result = curl_exec($ch); $result_array = json_decode($raw_result);
收到错误:
"must provide at least one product"
解决方案
- 确认账户授权产品:登录Plaid后台,查看你的账户已启用的产品列表,只有这些产品能在
products参数中使用。 - 选择合法初始产品:
balance属于后续可添加的产品,不能作为初始产品传入。初始支持的产品包括transactions、identity等(以你的账户授权为准)。 - 正确设置参数:选择一个或多个账户已授权的初始产品,例如如果账户启用了
transactions,则设置$data["products"] = ["transactions"];。 - 检查环境匹配:测试阶段请使用沙箱环境地址
https://sandbox.plaid.com/link/token/create,避免生产环境的权限限制。
内容的提问来源于stack exchange,提问作者Roizy Kish
相关产品推荐
相关产品推荐

