Javascript Tableau缺少密码
我正在尝试使用Web数据连接器将数据提取到Tableau中。我从中提取数据的API具有基本身份验证 代码在WDC模拟器中运行得非常好,但在Tableau桌面上运行时失败。它抛出了这个错误- “缺少密码” 但是我集成了密码。(在模拟器中也可以正常工作)。谢谢你的帮助 HTML代码Javascript Tableau缺少密码,javascript,html,http-headers,tableau-api,basic-authentication,Javascript,Html,Http Headers,Tableau Api,Basic Authentication,我正在尝试使用Web数据连接器将数据提取到Tableau中。我从中提取数据的API具有基本身份验证 代码在WDC模拟器中运行得非常好,但在Tableau桌面上运行时失败。它抛出了这个错误- “缺少密码” 但是我集成了密码。(在模拟器中也可以正常工作)。谢谢你的帮助 HTML代码 <html> <head> <title>API Fetch</title> <meta http-equiv="Cache-Control" con
<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>
API获取
获取存储数据!
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
});
});
})();
(函数(){
//创建连接器对象
var myConnector=tableau.makeConnector();
//设置基本授权标头
$.ajaxSetup({
标题:{'Authorization':“Basic”+btoa(“我的用户名”+“:”+“我的密码”)}
})
myConnector.init=函数(initCallback){
tableau.authType=tableau.authTypeEnum.basic;
initCallback();
};
//定义模式
myConnector.getSchema=函数(schemaCallback){
var cols=[{
id:“名称”,
别名:“姓名”,
数据类型:tableau.dataTypeEnum.string
}, {
id:“大小”,
别名:“大小”,
数据类型:tableau.dataTypeEnum.string
}, {
id:“时间戳”,
别名:“时间戳”,
数据类型:tableau.dataTypeEnum.datetime
}];
var tableSchema={
id:“存储”,
别名:“获取数据存储”,
列:cols
};
schemaCallback([tableSchema]);
};
//下载数据
myConnector.getData=函数(表,doneCallback){
$.getJSON(“https://my_API_URL,功能(resp){
var feat=相应内容,
tableData=[];
//迭代JSON对象
for(变量i=0,len=feat.length;i