【发布时间】:2020-06-06 13:50:22
【问题描述】:
我正在尝试关注 Plaid 的文档 from here,但当我在 Plaid 开发 环境中工作时,我似乎无法弄清楚从哪里获得 public_token。他们是这么说的:
在他们的第二个例子中:
from plaid import Client
client = Client(client_id='***', secret='***', public_key='***', environment='sandbox')
# the public token is received from Plaid Link
response = client.Item.public_token.exchange(public_token)
access_token = response['access_token']
我不知道public_token 来自哪里。如果我去Plaid Link,他们会说:
此存储库现已弃用。要与 Plaid 集成,请访问 文档。 https://plaid.com/docs
然后,当我访问他们的official docs 时,我似乎无法找到任何获取public token 的方法。
我正在尝试按照以下方式做一些事情:
from exceptions import (
InvalidPlaidEnvironment,
MissingPlaidCredential
)
from plaid import Client
from plaid.errors import APIError, ItemError, InvalidRequestError
VALID_ENVIRONMENTS = (
'sandbox',
'development',
'production'
)
CLIENT_ID = '<development_client_id>'
SECRET = '<development_secret>'
PUBLIC_KEY = '<development_public_key>'
ENVIRONMENT = 'development'
class PlaidProcessor:
"""
Simple processor class for Plaid API
"""
def __init__(
self,
client_id=CLIENT_ID,
secret=SECRET,
public_key=PUBLIC_KEY,
environment=ENVIRONMENT
):
"""
Constructor for PlaidProcessor. Initialize our class with basic credentials
data.
Args:
client_id (str): Plaid client ID
secret (str): Plaid secret
public_key (str): Plaid public key
environment (str): One of sandbox, development, or production
"""
self.client_id = client_id
self.secret = secret
self.public_key = public_key
self.environment = environment
if not self.client_id:
raise MissingPlaidCredential(
'Missing CLIENT_ID. Please provide Plaid client id.'
)
if not self.secret:
raise MissingPlaidCredential(
'Missing SECRET. Please provide Plaid secret.'
)
if not self.public_key:
raise MissingPlaidCredential(
'Missing PUBLIC_KEY. Please provide Plaid public key.'
)
if not self.environment:
raise MissingPlaidCredential(
'Missing environment. Please provide Plaid environment.'
)
if self.environment.lower() not in VALID_ENVIRONMENTS:
valid_environments_str = ','.join(VALID_ENVIRONMENTS)
raise InvalidPlaidEnvironment(
f'Please insert one of the following environments: {valid_environments_str}'
)
self.client = Client(
client_id=self.client_id,
secret=self.secret,
public_key=self.public_key,
environment=self.environment
)
self.access_token = None
self.public_token = None
def get_public_token(self):
# how do I get the access token?
pass
在文档中,他们还指定了以下内容:
public_token(在您的链接onSuccess()回调中返回) 应该被传递给你的服务器,服务器会将其交换为access_token。 public_tokens 是一次性使用的令牌,在之后过期 30分钟。您可以根据需要通过 /item/public_token/create 端点。
access_token用于访问项目的产品数据。这 应该安全地存储,而不是在客户端代码中。这是使用 为用户向 Plaid API 发出经过身份验证的请求。经过 默认情况下,access_tokens 不会过期,但您可以轮换它们;如果 它以错误状态结束,如果访问令牌将再次工作 项目的错误已解决。每个 access_token 对特定的 项,不能用于访问其他项。
但这更令人困惑。有人可以给我一些建议吗?
【问题讨论】:
标签: python-3.x plaid