-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpg.js
32 lines (29 loc) · 1.33 KB
/
pg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// const youtubeId = ``;
// const apiKey = ``;
// let url = `https://youtube.googleapis.com/youtube/v3/search?part=snippet&channelId=${youtubeId}&maxResults=10&order=date&key=${apiKey}`;
fetch(
"https://youtube.googleapis.com/youtube/v3/search?part=snippet&channelId=UCSjSmjY9cEI_ib-NrBElVXw&maxResults=10&order=date&key=AIzaSyAleOviVf7UxzBqbViyZ3Zw40ySQVlu6ys"
)
.then((result) => {
return result.json();
})
.then((data) => {
console.log(data);
let videos = data.items;
//Using for of loop we can fetch all contents
for (vid of videos) {
//Getting all contents from Youtube api
const id = vid.id.videoId;
const image = vid.snippet.thumbnails.high.url;
//Getting div from api.html
const iframeDiv = document.getElementById("fetchYt");
// iframeDiv.innerHTML = `<div class="col-md-6 white mt-3">
// <div class="ratio ratio-16x9 yt-bd">
// <iframe src="https://www.youtube.com/embed/${id}?rel=0" title="YouTube video" allowfullscreen></iframe>
// </div>`
iframeDiv.insertAdjacentHTML('beforeend', `<div class="col-md-6 white mt-3">
<div class="ratio ratio-16x9 yt-bd">
<iframe src="https://www.youtube.com/embed/${id}?rel=0" title="YouTube video" allowfullscreen></iframe>
</div>`);
}
});