Javascript 与Back4App的格子线链接集成

Javascript 与Back4App的格子线链接集成,javascript,html,node.js,parse-platform,plaid,Javascript,Html,Node.js,Parse Platform,Plaid,对开发人员来说是新手,只是将plaid link integration()直接复制并粘贴到客户端代码的基本HTML页面中,服务器端代码直接复制并粘贴到back4app的云代码(Node JS)中,并从云调用函数,但什么都没有发生,我收到了以下错误: 获取API无法加载file:///create_link_token. 对于CORS请求,URL方案必须为“http”或“https” index2.html:42未捕获(承诺中)类型错误:无法获取 在fetchLinkToken(index2.h

对开发人员来说是新手,只是将plaid link integration()直接复制并粘贴到客户端代码的基本HTML页面中,服务器端代码直接复制并粘贴到back4app的云代码(Node JS)中,并从云调用函数,但什么都没有发生,我收到了以下错误:

  • 获取API无法加载file:///create_link_token. 对于CORS请求,URL方案必须为“http”或“https”
  • index2.html:42未捕获(承诺中)类型错误:无法获取 在fetchLinkToken(index2.html:42)
  • parse.min.js:13 POST 400
  • parse.min.js:13未捕获(承诺中)错误:无效函数:“plaidAPI” 在handleError
  • 我的Html代码如下:

    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width">
      <script type="text/javascript"  src="https://cdnjs.cloudflare.com/ajax/libs/parse/2.1.0/parse.js"></script>
      <script type="text/javascript" src="https://npmcdn.com/parse/dist/parse.min.js"></script>
      <title>JS Bin</title>
      <style>
        .inputs{
          margin: 30px 0px;
        }
        .inputs input{
          margin: 5px 0px;
          height: 20px;
        }
      </style>
    </head>
    <body>
    <div align="center">
       <div class="title">
         <h1>Test</h1>
       </div>
    </div>
    <button id="link-button">Link Account</button>
    <script src="js/credentials.js"></script>
    <script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
    <script src="js/server.js"></script>
    <script type="text/javascript">
    (async function($) {
      const fetchLinkToken = async () => {
        const response = await fetch('/create_link_token', { method: 'POST' });
        const responseJSON = await response.json();
        return responseJSON.link_token;
      };
    
      const configs = {
     
        token: await fetchLinkToken(),
        onLoad: function() {
          // Optional, called when Link loads
        },
        onSuccess: async function(public_token, metadata) {
          
          await fetch('/get_access_token', {
            method: 'POST',
            body: JSON.stringify({ public_token: public_token }),
          });
        },
        onExit: async function(err, metadata) {
          // The user exited the Link flow.
          if (err != null) {
            // The user encountered a Plaid API error prior to exiting.
            if (err.error_code === 'INVALID_LINK_TOKEN') {
              
              handler.destroy();
              handler = Plaid.create({
                ...configs,
                token: await fetchLinkToken(),
              });
            }
          }
          
        },
        onEvent: function(eventName, metadata) {
          }
        }
      };
    
      let handler = Plaid.create(configs);
    
    
      $('#link-button').on('click', function(e) {
        handler.open();
      });
    })(jQuery);
    </script>
    <script id="plaid">
      Parse.Cloud.run("plaidAPI")
      </script>
    
    
    
    </body>
    
    
    
    </body>
    </html>
    

    需要通过快速路线启动节点,而不是调用云代码。

    首先需要决定是创建节点还是创建节点。您当前正在创建一个自定义快速路线,并将其作为云代码函数调用。
    
    var bodyParser = require('body-parser');
    var express = require('express');
    var plaid = require('plaid');
    
    // We store the access_token in memory - in production, store it in
    // a secure persistent data store.
    let ACCESS_TOKEN = null;
    let ITEM_ID = null;
    
    const client = new plaid.Client({
      clientID: 'Hidden-For-Obvious-Reasons',
      secret: 'Hidden-For-Obvious-Reasons',
      env: plaid.environments.sandbox
    });
    
    const app = express();
    
    // Create a link_token to initialize Link
    app.post('/create_link_token', async function(request, response, next) {
      // Grab the client_user_id by searching for the current user in your database
      const user = await User.find(...);
      const clientUserId = user.id;
    
      // Create the link_token with all of your configurations
      client.createLinkToken({
        user: {
          client_user_id: clientUserId,
        },
        client_name: 'My App',
        products: ['transactions'],
        country_codes: ['US'],
        language: 'en',
        webhook: 'https://sample.webhook.com',
      }, function(error, linkTokenResponse) {
        // Pass the result to your client-side app to initialize Link
        response.json({ link_token: linkTokenResponse.link_token });
      });
    });
    
    // Accept the public_token sent from Link
    app.post('/get_access_token', function(request, response, next) {
      const public_token = request.body.public_token;
      client.exchangePublicToken(public_token, function(error, response) {
        if (error != null) {
          console.log('Could not exchange public_token!' + '\n' + error);
          return response.json({error: msg});
        }
    
        // Store the access_token and item_id in your database
        ACCESS_TOKEN = response.access_token;
        ITEM_ID = response.item_id;
    
        console.log('Access Token: ' + ACCESS_TOKEN);
        console.log('Item ID: ' + ITEM_ID);
        response.json({'error': false});
      });
    });
    app.listen(8000);
    }