Gracenote API 调用获取 Programs/Shows
Gracenote API call to get Programs/Shows
我正在尝试通过 Gracenote API.
通过搜索查询(节目名称)来获取节目
供参考:
http://developer.tmsapi.com/io-docs (v1.1/programs/search)
使用他们网站上列出的示例(获取电影),效果很好。
http://developer.tmsapi.com/Sample_Code
<html>
<head>
<style type="text/css">
.tile {
display: inline-block;
border: 2px;
padding: 4px;
text-align: left;
font-size: 15px;
width:250px;
font-family: Avenir;
color: white;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
// construct the url with parameter values
var apikey = "xxxxx";
var baseUrl = "http://data.tmsapi.com/v1.1";
var showtimesUrl = baseUrl + '/movies/showings';
var zipCode = "78701";
var d = new Date();
var today = d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate();
$(document).ready(function() {
// send off the query
$.ajax({
url: showtimesUrl,
data: { startDate: today,
zip: zipCode,
jsonp: "dataHandler",
api_key: apikey
},
dataType: "jsonp",
});
});
// callback to handle the results
function dataHandler(data) {
$(document.body).append('<h2>Found ' + data.length + ' movies showing within 5 miles of ' + zipCode+'</h2>');
$.each(data, function(index, movie) {
var movieData = '<div class="tile"><img src="http://fanc.tmsimg.com/' + movie.preferredImage.uri + '?api_key='+apikey+'"><br/>';
movieData += 'Title:' + movie.title + '<br>';
movieData += 'ID: ' + movie.tmsId + '<br>';
if (movie.ratings) {movieData += 'Rating: ' + movie.ratings[0].code;}
else {movieData += 'Rating: ' + 'N/A';}
$(document.body).append(movieData);
});
}
</script>
</head>
<body>
</body>
</html>
当我试图修改它(获取程序)时,我未能检索到任何数据,所有数据都返回为未定义。
<html>
<head>
<style type="text/css">
.tile {
display: inline-block;
border: 2px;
padding: 4px;
text-align: left;
font-size: 15px;
width:250px;
font-family: Avenir;
color: white;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
// construct the url with parameter values
var apikey = "xxxxx";
var baseUrl = "http://data.tmsapi.com/v1.1";
var showtimesUrl = baseUrl + '/programs/search';
var zipCode = "78701";
var showName = 'Friends';
$(document).ready(function() {
// send off the query
$.ajax({
url: showtimesUrl,
data: { q: showName,
jsonp: "dataHandler",
api_key: apikey
},
dataType: "jsonp",
});
});
// callback to handle the results
function dataHandler(data) {
$(document.body).append('<h2>Found ' + data.length + ' movies showing within 5 miles of ' + zipCode+'</h2>');
var programs = data.hits;
$.each(data, function(index, program) {
var programData = '<div class="tile">' + program.entityType + '<br/>';
programData += 'Title:' + program.title + '<br>';
programData += 'ID: ' + program.tmsId + '<br>';
$(document.body).append(programData);
});
}
</script>
</head>
<body>
</body>
</html>
实际结果:(响应状态:200)
未定义
标题:未定义
ID:未定义
预期结果:(响应状态:200)
显示
标题:朋友
编号:SH001151270000
我可以通过查看数组来解决问题。
对于网站提供的电影示例代码,数组返回 属性 路径作为 [""0""].entityType 但对于程序它返回作为 点击[""0""].program.entityType.
所以我用data.hits和program.entityType[=26=替换了data ] 与 program.program.entityType 等
function dataHandler(data) {
$(document.body).append('<h2>Found ' + data.hits.length + ' shows.</h2>');
$.each(data.hits, function(index, program) {
var programData = '<div class="tile">' + program.program.entityType + '<br/>';
programData += 'Title:' + program.program.title + '<br>';
programData += 'ID: ' + program.program.tmsId + '<br>';
$(document.body).append(programData);
});
}
我正在尝试通过 Gracenote API.
通过搜索查询(节目名称)来获取节目供参考: http://developer.tmsapi.com/io-docs (v1.1/programs/search)
使用他们网站上列出的示例(获取电影),效果很好。
http://developer.tmsapi.com/Sample_Code
<html>
<head>
<style type="text/css">
.tile {
display: inline-block;
border: 2px;
padding: 4px;
text-align: left;
font-size: 15px;
width:250px;
font-family: Avenir;
color: white;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
// construct the url with parameter values
var apikey = "xxxxx";
var baseUrl = "http://data.tmsapi.com/v1.1";
var showtimesUrl = baseUrl + '/movies/showings';
var zipCode = "78701";
var d = new Date();
var today = d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate();
$(document).ready(function() {
// send off the query
$.ajax({
url: showtimesUrl,
data: { startDate: today,
zip: zipCode,
jsonp: "dataHandler",
api_key: apikey
},
dataType: "jsonp",
});
});
// callback to handle the results
function dataHandler(data) {
$(document.body).append('<h2>Found ' + data.length + ' movies showing within 5 miles of ' + zipCode+'</h2>');
$.each(data, function(index, movie) {
var movieData = '<div class="tile"><img src="http://fanc.tmsimg.com/' + movie.preferredImage.uri + '?api_key='+apikey+'"><br/>';
movieData += 'Title:' + movie.title + '<br>';
movieData += 'ID: ' + movie.tmsId + '<br>';
if (movie.ratings) {movieData += 'Rating: ' + movie.ratings[0].code;}
else {movieData += 'Rating: ' + 'N/A';}
$(document.body).append(movieData);
});
}
</script>
</head>
<body>
</body>
</html>
当我试图修改它(获取程序)时,我未能检索到任何数据,所有数据都返回为未定义。
<html>
<head>
<style type="text/css">
.tile {
display: inline-block;
border: 2px;
padding: 4px;
text-align: left;
font-size: 15px;
width:250px;
font-family: Avenir;
color: white;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
// construct the url with parameter values
var apikey = "xxxxx";
var baseUrl = "http://data.tmsapi.com/v1.1";
var showtimesUrl = baseUrl + '/programs/search';
var zipCode = "78701";
var showName = 'Friends';
$(document).ready(function() {
// send off the query
$.ajax({
url: showtimesUrl,
data: { q: showName,
jsonp: "dataHandler",
api_key: apikey
},
dataType: "jsonp",
});
});
// callback to handle the results
function dataHandler(data) {
$(document.body).append('<h2>Found ' + data.length + ' movies showing within 5 miles of ' + zipCode+'</h2>');
var programs = data.hits;
$.each(data, function(index, program) {
var programData = '<div class="tile">' + program.entityType + '<br/>';
programData += 'Title:' + program.title + '<br>';
programData += 'ID: ' + program.tmsId + '<br>';
$(document.body).append(programData);
});
}
</script>
</head>
<body>
</body>
</html>
实际结果:(响应状态:200)
未定义
标题:未定义
ID:未定义
预期结果:(响应状态:200)
显示
标题:朋友
编号:SH001151270000
我可以通过查看数组来解决问题。
对于网站提供的电影示例代码,数组返回 属性 路径作为 [""0""].entityType 但对于程序它返回作为 点击[""0""].program.entityType.
所以我用data.hits和program.entityType[=26=替换了data ] 与 program.program.entityType 等
function dataHandler(data) {
$(document.body).append('<h2>Found ' + data.hits.length + ' shows.</h2>');
$.each(data.hits, function(index, program) {
var programData = '<div class="tile">' + program.program.entityType + '<br/>';
programData += 'Title:' + program.program.title + '<br>';
programData += 'ID: ' + program.program.tmsId + '<br>';
$(document.body).append(programData);
});
}