2013-12-20 1 views
1

사용자가 YouTube API에서 검색 할 두 개의 키워드를 넣을 수있는 웹 사이트를 만들고 있지만 문제가 있습니다. 때때로 비디오 대신 채널을 반환합니다. 어떻게하면 비디오 만 반환 할 수 있습니까?YouTube API는 동영상 만 검색합니다.

이것은 현재 코드입니다. 비디오 : 함수 대해 GetRequest(), 검색 옵션에서 "종류"를 삭제하고 type을 설정해야합니다에서

// Your use of the YouTube API must comply with the Terms of Service: 
// https://developers.google.com/youtube/terms 
var YT = 'undefined'; 
// Helper function to display JavaScript value on HTML page. 
function showResponse(response) { 
    YT = response; 
} 

// Called automatically when JavaScript client library is loaded. 
function onClientLoad() { 
    gapi.client.load('youtube', 'v3', onYouTubeApiLoad); 
} 

// Called automatically when YouTube API interface is loaded (see line 9). 
function onYouTubeApiLoad() { 
    // This API key is intended for use only in this lesson. 
    // See http://goo.gl/PdPA1 to get a key for your own applications. 
    gapi.client.setApiKey('AIzaSyD49-XZ2JV7Rws3KDM2T7nA56Jbi-O7djY'); 
} 

function getRequest() { 
    var request = gapi.client.youtube.search.list({ 
     part: 'snippet', 
     kind: 'youtube#video', 
     q: document.getElementById("artiest").value + " - " + document.getElementById("nummer").value, 
    }); 

    // Send the request to the API server, 
    // and invoke onSearchRepsonse() with the response. 
    return request; 

} 

$(document).ready(function() { 
    $('#muziek').on('submit', function() { 
     var request = getRequest(); 
     request.execute(function(response) { 
      $('#muziek').unbind('submit'); 
      YT = response; 
      document.getElementById("VideoURL").value = YT.items[0].id.videoId; 
      $('#muziek').submit(); 
     });  
     return false; 
    }); 
}); 
+0

누구나? 선언 한 종류가 작동하지 않습니다. – joostmakaay

답변