Home > Backend Development > Golang > Grid link-initialize.js always displays the loading symbol

Grid link-initialize.js always displays the loading symbol

WBOY
Release: 2024-02-06 10:30:04
forward
635 people have browsed it

格子 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!

source:stackoverflow.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template