KaranManral
KaranManral

Reputation: 694

Getting search results for a category from the YouTube API

I am having trouble finding the right query for Youtube API Docs for my problem as the documentation is quite large.

How can I display youtube videos for some specific category like Travelling or Technical with max 30 results also how can I get the results for searching a particular keyword

My initial code on Express.js :

app.get("/videos2", (req, res) => {
  const url2 = "https://www.googleapis.com/youtube/v3/videos";
  fetch(`${url2}&key=${process.env.GOOGLE_API_KEY}`)
    .then((response) => {
      return response.json();
    })
    .then((json) => {
      res.json(json);
    });
});



Upvotes: 3

Views: 206

Answers (1)

Rakesh Sinha
Rakesh Sinha

Reputation: 91

use

sync function getAllUrls(urls) {
    try {
      var data = await Promise.all(
        urls.map((url) =>
          fetch(url)
            .then((response) => {
              return response.json();
            })
            .then((json) => {
              return json.items;
            })
        )
      );
      return data;
    } catch (error) {
      console.log(error);
      throw error;
    }
  }

Upvotes: 1

Related Questions