【发布时间】:2016-03-23 15:55:38
【问题描述】:
我有这个代码,我尝试用var v = value.statistics.viewCount; 进行一些更改,但对我没有任何作用,我试图找到答案但没有任何结果...
$(document).ready(function () {
$( $grid ).masonry( 'reloadItems' );
$( $grid ).masonry( 'layout' );
$('.add1').click(function (event) {
event.preventDefault();
var searchTerm = $('#query').val();
getRequest(searchTerm);
});
});
function getRequest(searchTerm) {
url = 'https://www.googleapis.com/youtube/v3/search';
var params = {
part: 'snippet',
key: 'AIzaSyA8OmKcw2DMNkJicyCJ0vqvf90xgeH52zE',
q: searchTerm,
maxResults:10
};
$.getJSON(url, params, function (searchTerm) {
showResults(searchTerm);
});
}
function showResults(results) {
var html = "";
var entries = results.items;
$.each(entries, function (index, value) {
var title = value.snippet.title;
var thumbnail = value.snippet.thumbnails.high.url;
var v = value.statistics.viewCount;
var description = value.snippet.description;
var videoID = value.id.videoId;
html += '<div class="item" title="' + title + '">' + '<img class= "vidth" id="' + videoID + '" src="' + thumbnail + '" ><div class="info"><p1>' + title+'</p1><hr><p2>'+description+'</p2><hr><p3>'+v+'</p3></div></div>';
});
$('.masonry').append(html);
$( $grid ).masonry( 'reloadItems' );
$( $grid ).masonry( 'layout' );
}
【问题讨论】:
-
没有
viewCount和搜索列表资源,查看api -
真的不知道吗?你能帮忙吗?
-
检查这个答案 stackoverflow.com/a/35615051/2274530 代码从播放列表中的所有视频中检索 viewCount
标签: youtube-api views