Tableau缺少密码

时间:2018-06-11 07:21:01

标签: javascript html http-headers tableau basic-authentication

我正在尝试使用Web数据连接器将数据提取到Tableau中。我从中提取数据的API有Basic Auth。

代码在WDC Simulator中运行得非常好但是从Tableau Desktop运行时失败了。它抛出了这个错误 -

  

"缺少密码"

但我已经整合了密码。 (它在模拟器中工作正常)。任何帮助表示赞赏

HTML代码

<html>
<head>
    <title>API Fetch</title>
    <meta http-equiv="Cache-Control" content="no-store" />

     <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" ></script>

    <script src="https://connectors.tableau.com/libs/tableauwdc-2.0.latest.js" type="text/javascript"></script>
    <script src="my_js_above.js" type="text/javascript"></script>

</head>

<body>
    <div class="container container-table">
        <div class="row vertical-center-row">
            <div class="text-center col-md-4 col-md-offset-4">
                <button type = "button" id = "submitButton" class = "btn btn-success" style = "margin: 10px;">Get Storage Data!</button>
            </div>
        </div>
    </div>
</body>


</html>

JS代码

(function() {


// Create the connector object
    var myConnector = tableau.makeConnector();

//Setting up the Basic Authorization Header
$.ajaxSetup({
    headers: {'Authorization': "Basic " + btoa("my_username" + ":" + "my_password")}
})

     myConnector.init = function(initCallback) {
      tableau.authType = tableau.authTypeEnum.basic;
      initCallback();
  };

    // Define the schema
    myConnector.getSchema = function(schemaCallback) {
        var cols = [{
            id: "Name",
            alias: "Name",
            dataType: tableau.dataTypeEnum.string
        }, {
            id: "Size",
            alias: "Size",
            dataType: tableau.dataTypeEnum.string
        }, {
            id: "timeStamp",
            alias: "Timestamp",
            dataType: tableau.dataTypeEnum.datetime
        }];

        var tableSchema = {
            id: "Storage",
            alias: "Fetches data storage",
            columns: cols
        };

        schemaCallback([tableSchema]);
    };

    // Download the data
    myConnector.getData = function(table, doneCallback) {
        $.getJSON("https://my_API_URL", function(resp) {
            var feat = resp.content,
                tableData = [];

            // Iterate over the JSON object
            for (var i = 0, len = feat.length; i < len; i++) {
                tableData.push({
                    "Name": feat[i].Name,
                    "Size": feat[i].Size,
                    "timeStamp": feat[i].timeStamp
                });
            }

            table.appendRows(tableData);
            doneCallback();
        });
    };

    tableau.registerConnector(myConnector);
    // Create event listeners for when the user submits the form
    $(document).ready(function() {
        $("#submitButton").click(function() {
            tableau.connectionName = "Storage"; // This will be the data source name in Tableau
            tableau.submit(); // This sends the connector object to Tableau
        });
    });
})();

0 个答案:

没有答案