-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
47 lines (33 loc) · 1.62 KB
/
api.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 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 divImg = document.getElementById("YtImage");
const iframeDiv = document.getElementById("fetchYt");
//Createing a iframes using javascript
iframeYt = document.createElement('iframe');
iframeYt.src = `https://www.youtube.com/watch?v=${id}`;
//Creating a image element and intializing attributes
const imageDiv = document.createElement('div');
const imageElement = document.createElement('img');
imageElement.src = image;
imageElement.classList.add("col-md-6");
//Inserting a image elements in child from parent div
imageDiv.append(imageElement);
divImg.appendChild(imageElement);
//Generating outputs in cansole log
console.log(`https://www.youtube.com/watch?v=${id}`);
// document.write(`<img src="${image}" alt="">`);
}
})