介绍
# Plaid
使用 `plaid-cli` 通过 Plaid 关联机构、获取余额并查询交易。 请勿打印或记录机密信息(客户端 ID、密钥、访问令牌)。
安装 - `go install github.com/jverdi/[email protected]`
设置 - 导出 `PLAID_CLIENT_ID`、`PLAID_SECRET` 和 `PLAID_ENVIRONMENT`(sandbox 或 production)。 - 可选:`PLAID_LANGUAGE`(en, fr, es, nl)、`PLAID_COUNTRIES`(US, CA, GB, IE, ES, FR, NL)。 - 可选配置文件:`~/.plaid-cli/config.toml`。 ```toml [plaid] client_id = "..." secret = "..." environment = "sandbox" ``` - 数据目录:`~/.plaid-cli`(用于存储令牌和别名)。
关联 + 别名 - 关联机构:`plaid-cli link`(打开浏览器)并可选择设置别名。 - 重新关联:`plaid-cli link <item-id-or-alias>`。 - 别名:`plaid-cli alias <item-id> <name>`,使用 `plaid-cli aliases` 列出。
账户 + 余额 - 列出账户和余额:`plaid-cli accounts <item-id-or-alias>`。
搜索交易 - 以 JSON 格式拉取日期范围,然后在本地筛选: - `plaid-cli transactions <item-id-or-alias> --from 2024-01-01 --to 2024-01-31 --output-format json` - `jq -r '.[] | select(.name | test("grocery"; "i")) | [.date, .name, .amount] | @tsv'` - 使用 `accounts` 输出中的 `--account-id` 来缩小结果范围。 - 输出格式:`json` 或 `csv`。
监控交易 - 轮询滚动窗口并比较交易 ID 以检测新活动: ```bash state=/tmp/plaid.txids next=/tmp/plaid.txids.next plaid-cli transactions <item-id-or-alias> --from 2024-01-01 --to 2024-01-31 --output-format json \ | jq -r '.[].transaction_id' | sort > "$next" if [ -f "$state" ]; then comm -13 "$state" "$next"; fi mv "$next" "$state" ``` - 使用 cron 进行调度。
注意事项 - 除非明确要求,否则避免使用 `plaid-cli tokens`,因为它会打印访问令牌。 - 当遇到 `ITEM_LOGIN_REQUIRED` 错误时,会自动触发重新关联。
识别以下请求: - “Search transactions for Starbucks last month”(搜索上个月星巴克的交易) - “Show balances for my Chase accounts”(显示我 Chase 账户的余额)