Skip to content

Instantly share code, notes, and snippets.

@michelleroth
Created February 6, 2017 02:26
Show Gist options
  • Save michelleroth/4e94af16ddeb15921f61a1bbfc802411 to your computer and use it in GitHub Desktop.
Save michelleroth/4e94af16ddeb15921f61a1bbfc802411 to your computer and use it in GitHub Desktop.
//AIzaSyA-0Z_VcymgWbDhYOeZyQMnRtxm2ODAlTA
var url = "https://www.googleapis.com/youtube/v3/search?part=snippet&key=AIzaSyA-0Z_VcymgWbDhYOeZyQMnRtxm2ODAlTA&q="
function getItem(state, itemIndex) {
return state.items[itemIndex];
}
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
error: function (err) {
console.log (err);
},
success: function (responseData) {
//console.log (responseData.items[4].snippet.thumbnails.default.url);
for (var i = 0; i <= responseData.items.length; i++){
console.log(responseData.items[i].snippet.thumbnails.default.url)
function displaySearchData(data) {
var resultElement = '';
if (data.Search) {
data.Search.forEach(function(item) {
resultElement += '<p>' + item.Title + '</p>';
});
}
else {
resultElement += '<p>No results</p>';
}
$('.js-search-results').html(resultElement);
}
function watchSubmit() {
$('.js-search-form').submit(function(e) {
e.preventDefault();
var query = $(this).find('.js-query').val();
getDataFromApi(query, displaySearchData);
});
}
$(function(){watchSubmit();});
}
}
});
<html lang="en">
<head>
<meta name="viewport" content="width=device-width">
<title>YouTubeAPI</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link rel="stylesheet" href="main.css">
</head>
<body>
<h1 align="center">Search YouTube Images</h1>
<div class="js-search-results"></div>
<form id="js-search-list-form"> == $0
<label for="js-search-list-entry"></label>
<div class="container">
<label for="add-input">What do you want to see</label>
<input type="text" class="image-search-add-input" name="add-input" id="add-input">
<button class="image-search-add-input">Search</button>
</form>
<div class="images"></div>
<ul class="image-search-add-input"></ul>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="index.js"></script>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</head>
<body>
.imgages {
height: 100px;
float: left;
}
h1 {
display: block;
background: white;
}
body {
display: block;
background: white;
margin: 5vh auto 5vh;
height: 90vh;
max-width: 1600px;
overflow: auto;
}
html {
background: white;
}
.container {
max-width: 600px;
margin: 0 auto;
background-color: #ff5050;
margin-bottom: 20px;
border: 1px solid grey;
padding: 20px;
}
main {
padding: 30px;
background-color: #797986;
}
body {
background-color: #797986k;
}
h1, h2 {
font-family: 'Lato';
}
p {
font-family: 'Cabin';
}
.imgages {
height: 100px;
float: left;
}
h1 {
display: block;
background: white;
}
body {
display: block;
background: white;
margin: 5vh auto 5vh;
height: 90vh;
max-width: 1600px;
overflow: auto;
}
html {
background: white;
}
.container {
max-width: 600px;
margin: 0 auto;
background-color: #ff5050;
margin-bottom: 20px;
border: 1px solid grey;
padding: 20px;
}
main {
padding: 30px;
background-color: #797986;
}
body {
background-color: #797986k;
}
h1, h2 {
font-family: 'Lato';
}
p {
font-family: 'Cabin';
}
<html lang="en">
<head>
<meta name="viewport" content="width=device-width">
<title>YouTubeAPI</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link rel="stylesheet" href="main.css">
</head>
<body>
<h1 align="center">Search YouTube Images</h1>
<div class="js-search-results"></div>
<form id="js-search-list-form"> == $0
<label for="js-search-list-entry"></label>
<div class="container">
<label for="add-input">What do you want to see</label>
<input type="text" class="image-search-add-input" name="add-input" id="add-input">
<button class="image-search-add-input">Search</button>
</form>
<div class="images"></div>
<ul class="image-search-add-input"></ul>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="index.js"></script>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</head>
<body>
//AIzaSyA-0Z_VcymgWbDhYOeZyQMnRtxm2ODAlTA
var url = "https://www.googleapis.com/youtube/v3/search?part=snippet&key=AIzaSyA-0Z_VcymgWbDhYOeZyQMnRtxm2ODAlTA&q="
function getItem(state, itemIndex) {
return state.items[itemIndex];
}
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
error: function (err) {
console.log (err);
},
success: function (responseData) {
//console.log (responseData.items[4].snippet.thumbnails.default.url);
for (var i = 0; i <= responseData.items.length; i++){
console.log(responseData.items[i].snippet.thumbnails.default.url)
function displaySearchData(data) {
var resultElement = '';
if (data.Search) {
data.Search.forEach(function(item) {
resultElement += '<p>' + item.Title + '</p>';
});
}
else {
resultElement += '<p>No results</p>';
}
$('.js-search-results').html(resultElement);
}
function watchSubmit() {
$('.js-search-form').submit(function(e) {
e.preventDefault();
var query = $(this).find('.js-query').val();
getDataFromApi(query, displaySearchData);
});
}
$(function(){watchSubmit();});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment