Plaid API 获取访问令牌 java android

发布于 2025-01-11 11:22:47 字数 1253 浏览 3 评论 0原文

我是与 API 通信的初学者,目前正在使用 Plaid API 来检索 Android 应用程序的交易数据。目前,我已成功与 Plaid Link 集成,并且可以通过应用程序获取公共令牌,但是我现在在将公共令牌交换为访问令牌时遇到问题。我从这里获取公共令牌:

private ActivityResultLauncher<LinkTokenConfiguration> linkAccountToPlaid = registerForActivityResult(
      new OpenPlaidLink(),
      result -> {
        if (result instanceof LinkSuccess) {
            //Exchange public token for persistent access token

我相信服务器上的以下代码用于交换公共令牌:

app.post('/api/set_access_token', function (request, response, next) {
  PUBLIC_TOKEN = request.body.public_token;
  Promise.resolve()
    .then(async function () {
      const tokenResponse = await client.itemPublicTokenExchange({
        public_token: PUBLIC_TOKEN,
      });
      prettyPrintResponse(tokenResponse);
      ACCESS_TOKEN = tokenResponse.data.access_token;
      ITEM_ID = tokenResponse.data.item_id;
      if (PLAID_PRODUCTS.includes('transfer')) {
        TRANSFER_ID = await authorizeAndCreateTransfer(ACCESS_TOKEN);
      }
      response.json({
        access_token: ACCESS_TOKEN,
        item_id: ITEM_ID,
        error: null,
      });
    })
    .catch(next);
});

我正在运行快速启动服务器,我的问题是,如何调用服务器来交换公共令牌对于访问令牌?或者换句话说,如何进行后调用,其中包含服务器的公共令牌以接收访问令牌

I am a beginner with communicating with APIs and I am currently working with the Plaid API in order to retrieve transaction data for an android application. Currently, I have successfully integrated with the Plaid Link and can obtain public tokens through the app, however I am now having trouble exchanging the public token for the access token. I obtain the public token from here:

private ActivityResultLauncher<LinkTokenConfiguration> linkAccountToPlaid = registerForActivityResult(
      new OpenPlaidLink(),
      result -> {
        if (result instanceof LinkSuccess) {
            //Exchange public token for persistent access token

I believe the following code on the server is used to exchange the public token:

app.post('/api/set_access_token', function (request, response, next) {
  PUBLIC_TOKEN = request.body.public_token;
  Promise.resolve()
    .then(async function () {
      const tokenResponse = await client.itemPublicTokenExchange({
        public_token: PUBLIC_TOKEN,
      });
      prettyPrintResponse(tokenResponse);
      ACCESS_TOKEN = tokenResponse.data.access_token;
      ITEM_ID = tokenResponse.data.item_id;
      if (PLAID_PRODUCTS.includes('transfer')) {
        TRANSFER_ID = await authorizeAndCreateTransfer(ACCESS_TOKEN);
      }
      response.json({
        access_token: ACCESS_TOKEN,
        item_id: ITEM_ID,
        error: null,
      });
    })
    .catch(next);
});

I have the quickstart server running, my question is, how do I then make the call to the server to exchange the public token for the access token? or in other words, how do I make a post call, containing the public token to the server to receive the access token

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请持续率性 2025-01-18 11:22:47

Plaid Android 团队的回应:

因此,在我们的 GitHub 上的 Android 快速入门示例中,我们已经设置 Retrofit API 来检索 link_token

你想要做的是添加类似的东西

  @POST("/api/get_transactions")
  fun getTransactions(publicToken: PublicToken): Single<Transactions>

data class PublicToken(@SerializedName("public_token") publicToken: String)

data class Transactions( @SerializedName("transactions") val transactions: List<Transaction>
)

data class Transaction( @SerializedName("amount") val amount: Float, 
@SerializedName("category") val category: String, 
)

Response from the Plaid Android team:

So in our Android quickstart sample on GitHub, we already have a Retrofit API set up to retrieve the link_token.

What you would want to do is to add something like

  @POST("/api/get_transactions")
  fun getTransactions(publicToken: PublicToken): Single<Transactions>

data class PublicToken(@SerializedName("public_token") publicToken: String)

data class Transactions( @SerializedName("transactions") val transactions: List<Transaction>
)

data class Transaction( @SerializedName("amount") val amount: Float, 
@SerializedName("category") val category: String, 
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文