Last active
June 5, 2021 13:04
-
-
Save philmein23/19f4290821fc36b696aa to your computer and use it in GitHub Desktop.
youtube
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
$("#search-term").submit(function(event) { | |
event.preventDefault(); | |
var searchTerm = $("#query").val(); | |
getRequest(searchTerm); | |
}) | |
function getRequest(searchTerm) { | |
var params = { | |
part: 'snippet', | |
id: 'videoId', | |
key: 'AIzaSyAJH04pfGBf6N34ileppDhtSd5GMZqecto', | |
q: searchTerm | |
}; | |
url = 'https://www.googleapis.com/youtube/v3/search'; | |
$.getJSON(url, params, function(data){ | |
console.log(data); | |
showResults(data.items); | |
}) | |
} | |
function showResults(results) { | |
var html = ""; | |
for (var i = 0; i < results.length; i++) { | |
var myData = results[i].snippet.thumbnails.medium.url; | |
var myVideoId = results[i].id.videoId; | |
html += "<p><a href='http://www.youtube.com/watch?v=' +myVideoId><img src='"+ myData +"'></a></p>"; | |
console.log(myData); | |
} | |
$("#search-results").html(html); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment