api - Yelp Tableau Web 数据连接器
问题描述
我是 Tableau Web 数据连接器和编程的新手,但我正在尝试创建一个 yelp 数据连接器。
- 我使用邮递员测试了 API,它工作正常。
- 我将 tableau github 提供的示例 Earth quake js 代码片段复制到了我的 Yelp.js 中。
- API 还需要一个我添加到我的 Yelp.js 文件中的私有 API 密钥。
当我按下获取数据时,会弹出 WDC 验证错误。
以下是控制台中的错误消息:
“数据类型不能为空”
这是我拥有的 Yelp.js 文件,不太确定错误消息指的是什么?
定义数据源将具有的架构<-- 似乎这个架构是问题所在?但它不是空白..
myConnector.getSchema = function(schemaCallback) {
//Each item represents a column in tableau
var cols = [{
id: "term",
alias: "search term",
dataType: tableau.dataTypeEnum.string
}, {
id: "location",
alias: "location",
dataType: tableau.dataTypeEnum.string
}, {
id: "latitude",
alias: "lat",
dataType: tableau.dataTypeEnum.decimal
}, {
id: "longitude",
alias: "lon",
dataType: tableau.dataTypeEnum.decimal
}, {
id: "radius",
alias: "radius",
dataType: tableau.dataTypeEnum.tnteger
}, {
id: "open_now",
alias: "open now",
dataType: tableau.dataTypeEnum.boolean
}, {
id: "open_at",
alias: "open at",
dataType: tableau.dataTypeEnum.integer
}];
var tableInfo = {
id: "yelpsearch",
alias: "Yelp Business Search",
columns: cols
};
以下代码片段是下载数据
myConnector.getData = function(table, doneCallback) {
var term = "",
location = "",
latitude = 0,
longitude = 0,
radius = 0,
open_now = true,
open_at = 0;
复制自邮递员
var settings = {
"async": true,
"crossDomain": true,
"url": "https://api.yelp.com/v3/businesses/search",
"method": "GET",
"headers": {
"Authorization": "Bearer API KEY HERE",
"cache-control": "no-cache",
"Postman-Token": "POSTMAN TOKEN HERE"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
遍历 JSON 对象
$.getJSON("https://api.yelp.com/v3/businesses/search", function(resp) {
tableData = [];
for (var i = 0, len = resp.length; i < len; i++) {
tableData.push({
"term" : resp[i].term,
"location" : resp[i].location,
"latitude" : resp[i].latitude,
"longitude": resp[i].longitude,
"radius" : resp[i].radius,
"open_now" : resp[i].open_now,
"open_at" : resp[i].open_at,
});
}
table.appendRows(tableData);
doneCallback();
});
};
如果有人能对此有所了解,将不胜感激。谢谢!
这是 Yelp 的 API 文档
https://www.yelp.com/developers/documentation/v3/business_search
解决方案
推荐阅读
- mysql - SQL - 如何为每个用户检索 5 个最近的评论
- python - 如何在一组过滤行上使用 apply 和 lambda 函数
- python - 使用 Python 跟踪特定时间的 GPS 数据
- python - 是否可以在字典中列出一系列数字?
- highcharts - 如何添加下拉列表以更改显示 HTML 表中日期的图表中的 endRow 值
- python - 如何获得复杂形状多边形的中心线
- javascript - React Native 防止上下文依赖重新渲染所有组件
- drop-down-menu - Gravity Forms - 使用用户输入的信息动态填充下拉列表
- python - 需要在同一密集层中的权重之间进行数学运算
- javascript - 我不明白: for (var node = list; node; node = node.rest)