Table of Contents
正确答案
Home Backend Development Golang Grid link-initialize.js always displays the loading symbol

Grid link-initialize.js always displays the loading symbol

Feb 06, 2024 am 10:30 AM

格子 link-initialize.js 永远显示加载符号

问题内容

我正在尝试使用 Plaid 开发环境来测试 Plaid API。我正在为 plaid 创建一个命令行 cli,所以我目前不需要服务器,所以目前我使用 Go 生成一个链接令牌并将该令牌呈现为 HTML blob。当我在浏览器中打开该 HTML 文件并单击“链接帐户”按钮时,它会无限期挂起。

下面是生成链接并呈现为 HTML 的 go 代码:

package main

import (
    "context"
    _ "embed"
    "html/template"
    "log"
    "os"
    "time"

    "github.com/plaid/plaid-go/plaid"
    "github.com/vrischmann/envconfig"
)

type config struct {
    PlaidApi struct {
        ClientId string `envconfig:"PLAID_CLIENT_ID"`
        Secret   string `envconfig:"PLAID_SECRET"`
    }
}

//go:embed token.html.tmpl
var tokenPage string

func main() {
    cfg := config{}

    if err := envconfig.Init(&cfg); err != nil {
        log.Fatalf("failed to load config from environment: %s", err)
    }

    ctx := context.TODO()
    plaidCfg := plaid.NewConfiguration()
    plaidCfg.UseEnvironment(plaid.Development)
    cli := plaid.NewAPIClient(plaidCfg)
    phoneNumber := "+1 888 888-8888"
    user := plaid.LinkTokenCreateRequestUser{
        ClientUserId: "1",
        PhoneNumber:  &phoneNumber,
    }
    request := plaid.NewLinkTokenCreateRequest(
        "Personal Finance App",
        "en",
        []plaid.CountryCode{plaid.COUNTRYCODE_US},
        user,
    )
    request.SetProducts([]plaid.Products{plaid.PRODUCTS_TRANSACTIONS})
    request.SetSecret(cfg.PlaidApi.Secret)
    request.SetClientId(cfg.PlaidApi.ClientId)
    linkTokenCreateResp, _, err := cli.PlaidApi.LinkTokenCreate(ctx).LinkTokenCreateRequest(*request).Execute()
    if err != nil {
        if pErr, err := plaid.ToPlaidError(err); err == nil {
            log.Printf("Error from plaid: %s", pErr.ErrorMessage)
        }
        log.Fatalf("failed to get link request: %s", err.Error())
    }
    log.Printf("link token: %s", linkTokenCreateResp.GetLinkToken())

    tmplate, err := template.New("token.html").Parse(tokenPage)
    if err != nil {
        log.Printf("Html tmplate:\n%s", tokenPage)
        log.Fatalf("Failed to create HTML template: %s", err)
    }

    page, err := os.CreateTemp("", "catnip_*.html")
    if err != nil {
        log.Fatalf("Failed to create temp file: %s", err)
    }
    defer os.Remove(page.Name())
    data := struct {
        LinkToken string
    }{LinkToken: linkTokenCreateResp.LinkToken}
    if err := tmplate.Execute(page, data); err != nil {
        log.Printf("template data: %#v", data)
        log.Printf("html template:\n%#v", tokenPage)
        log.Fatalf("Failed to render token page: %s", err)
    }

    log.Printf("token page path:\n%s", page.Name())
    time.Sleep(2 * time.Minute)
}
Copy after login

这是模板(token.html.tmpl):

<button id="link-button">Link Account</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
<script type="text/javascript">
(async function($) {
  var handler = Plaid.create({
    // Create a new link_token to initialize Link
    token: "{{ .LinkToken }}",
    onLoad: function() {
        console.log("link token: '{{ .LinkToken }}")
    },
    onSuccess: function(public_token, metadata) {
        console.log("Success!");
    },
    onExit: function(err, metadata) {
      if (err != null) {
          console.log(err);
      }
    },
    onEvent: function(eventName, metadata) {}
  });

  $('#link-button').on('click', function(e) {
    handler.open();
  });
})(jQuery);
</script>
Copy after login
  • 查看控制台,没有看到任何错误
  • 查看网络流量,奇怪的是,单击按钮似乎没有产生任何流量

正确答案


我尝试手动创建链接令牌(使用格子邮差集合)并硬-将该链接令牌编码到您的 HTML 文件中。当我这样做时,它对我来说工作正常:按下按钮后,我短暂地看到了旋转器,然后弹出了一个链接窗口。

我建议你尝试同样的事情。如果它有效,那么问题要么与您如何在代码中生成链接令牌有关,要么与模板如何发送/摄取链接令牌有关。如果它不起作用,那么问题可能是客户端特定于您的配置的问题(例如,可能是浏览器插件阻止链接打开)?

The above is the detailed content of Grid link-initialize.js always displays the loading symbol. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the vulnerabilities of Debian OpenSSL What are the vulnerabilities of Debian OpenSSL Apr 02, 2025 am 07:30 AM

OpenSSL, as an open source library widely used in secure communications, provides encryption algorithms, keys and certificate management functions. However, there are some known security vulnerabilities in its historical version, some of which are extremely harmful. This article will focus on common vulnerabilities and response measures for OpenSSL in Debian systems. DebianOpenSSL known vulnerabilities: OpenSSL has experienced several serious vulnerabilities, such as: Heart Bleeding Vulnerability (CVE-2014-0160): This vulnerability affects OpenSSL 1.0.1 to 1.0.1f and 1.0.2 to 1.0.2 beta versions. An attacker can use this vulnerability to unauthorized read sensitive information on the server, including encryption keys, etc.

How do you use the pprof tool to analyze Go performance? How do you use the pprof tool to analyze Go performance? Mar 21, 2025 pm 06:37 PM

The article explains how to use the pprof tool for analyzing Go performance, including enabling profiling, collecting data, and identifying common bottlenecks like CPU and memory issues.Character count: 159

How do you write unit tests in Go? How do you write unit tests in Go? Mar 21, 2025 pm 06:34 PM

The article discusses writing unit tests in Go, covering best practices, mocking techniques, and tools for efficient test management.

What libraries are used for floating point number operations in Go? What libraries are used for floating point number operations in Go? Apr 02, 2025 pm 02:06 PM

The library used for floating-point number operation in Go language introduces how to ensure the accuracy is...

What is the problem with Queue thread in Go's crawler Colly? What is the problem with Queue thread in Go's crawler Colly? Apr 02, 2025 pm 02:09 PM

Queue threading problem in Go crawler Colly explores the problem of using the Colly crawler library in Go language, developers often encounter problems with threads and request queues. �...

How do you specify dependencies in your go.mod file? How do you specify dependencies in your go.mod file? Mar 27, 2025 pm 07:14 PM

The article discusses managing Go module dependencies via go.mod, covering specification, updates, and conflict resolution. It emphasizes best practices like semantic versioning and regular updates.

How do you use table-driven tests in Go? How do you use table-driven tests in Go? Mar 21, 2025 pm 06:35 PM

The article discusses using table-driven tests in Go, a method that uses a table of test cases to test functions with multiple inputs and outcomes. It highlights benefits like improved readability, reduced duplication, scalability, consistency, and a

Transforming from front-end to back-end development, is it more promising to learn Java or Golang? Transforming from front-end to back-end development, is it more promising to learn Java or Golang? Apr 02, 2025 am 09:12 AM

Backend learning path: The exploration journey from front-end to back-end As a back-end beginner who transforms from front-end development, you already have the foundation of nodejs,...

See all articles