그것은 간단합니다. 코드를 Youtube API와 통합하면 API (결과의 양, 날짜 등)를 사용하여 거의 모든 것을 설정할 수있는 결과와 같은 객체를 반환합니다. 그래서, 당신이 볼 수있는 것처럼 그것을 형성 할 수 있습니다.
function tplawesome(e,t){res=e;for(var n=0;n<t.length;n++){res=res.replace(/\{\{(.*?)\}\}/g,function(e,r){return t[n][r]})}return res}
$(function() {
$("#search-btn").on("click", function(e){
e.preventDefault();
//prepare the request
var request = gapi.client.youtube.search.list({
part: "snippet",
type: "video",
q: encodeURIComponent($("#input-search").val()).replace(/%20/g, "+"),
maxResults: 6,
order: "viewCount",
publishedAfter: "2015-01-01T00:00:00Z"
});
request.execute(function(response){
var results = response.result;
function getMonth(monthNumber){
var monthName = ['jan', 'fevereiro', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'];
return monthName[monthNumber-1];
}
var dateUTC = results.items[0].snippet.publishedAt;
var year = dateUTC.substring(0,4);
var day = dateUTC.substring(8,10);
var month = dateUTC.substring(5,7);
month = getMonth(month);
var finalDate = day + " de " + month + " de " + year;
console.log("passou", results.items[0].snippet.description);
//$.each(results.items, function(index, item){
$.get("youtube/item", function(data){
$("#results").append(tplawesome(data, [{ "videoId":results.items[0].id.videoId}]));
});
$.get("youtube/title", function(data){
$(".info-title").append(tplawesome(data,[{"title": results.items[0].snippet.title, "videoId":results.items[0].id.videoId}]));
});
$.get("youtube/description", function(data){
$(".info-description").append(tplawesome(data,[{"description": results.items[0].snippet.description, "videoId":results.items[0].id.videoId}]));
});
$.get("youtube/finalDate", function(data){
$(".publishedTime").append(tplawesome(data, [{finalDate}]));
});
$.get("youtube/relationVideo", function(data){
$(".relationVideo-container").append(tplawesome(data,[{"title": results.items[1].snippet.title, "videoId":results.items[1].id.videoId}]));
});
$.get("youtube/relationVideo", function(data){
$(".relationVideo-container").append(tplawesome(data,[{"title": results.items[2].snippet.title, "videoId":results.items[2].id.videoId}]));
});
});
});
});
function init(){ gapi.client.setApiKey("AIzaSyDuLpwiCe78V9p0JE5rQaygB2XVgIDHjhs");
gapi.client.load("youtube", "v3", function(){
//youtube API ok
});
}
$(document).ready(function(){
$("#search-btn").on("click", function(){
$('#info-section').addClass('show');
$('#video-section').addClass('show');
$('#description-section').addClass('show');
});
당신은 유튜브 API, NodeJS와 익스프레스 here 간단한 프로젝트를 볼 수 있습니다
다음은 결과에 어떤 치료와 jQuery를 예입니다.
서버를 사용하십시오. 자신 만의 빌드 방법을 모르는 경우 [diff bot] (https://www.diffbot.com/dev/docs/article/)를 사용하십시오. – ymz