I am using YouTube API key to fetch data on search.
const key = "[API Key]";
const url = "https://www.googleapis.com/youtube/v3/search";
$(document).ready(function () {
const options = {
part: ["snippet"],
key: key,
maxResults: 10,
q: "developers",
};
loadVids();
function loadVids() {
$.getJSON(url, options, function (data) {
const videos = data.items;
console.log(videos);
});
}
});
It is working properly but I want to convert $.getJSON() to async await using vanilla javascript. Please guide me how to do this.
2
Answers
I found a solution There is no need of part: ['snippet']. It is working properly without using that.
More understandable code
You can do it by defining a Promise function like:
and then await on it: