Skip to main content

Search YouTube with Google Script and YouTube API Easy Guide!

This article explains about Search YouTube with Google Script and YouTube API.

This Google Script demonstrates how to search for videos using keywords using the YouTube API, i.e., Search YouTube with Google Script and YouTube API. The source data is in a column in a Google Spreadsheet, and we use Google Apps Script to connect to the YouTube Data API. The project for the Google Cloud Platform ought to have the YouTube service enabled. You can use the below mentioned code to Search YouTube with Google Script and YouTube API.

Code for Search YouTube with Google Script and YouTube API:

function findYouTubeVideoByKeywords() {
  // get the search query from Google Sheets
  var sheet = SpreadsheetApp.getActiveSheet();
  var data = sheet.getDataRange().getValues();

  // iterate through all rows in the sheet
  for (var d = 1, l = data.length; d < l; d++) {
    // find the top result only
    var results = YouTube.Search.list('id,snippet', {
      q: data[d][0],
      maxResults: 1,
    });

    // was a matching video found on YouTube?
    if (results.pageInfo.totalResults !== 0) {
      var item = results.items[0];
      var snippet = item.snippet;
      var response = [
        item.id.videoId,
        snippet.title,
        snippet.description,
        new Date(snippet.publishedAt),
        snippet.channelId,
        snippet.channelTitle,
        snippet.thumbnails['default']['url'],
      ];
      // write the response to Google Sheet
      sheet.getRange(d + 1, 4, 1, response.length).setValues([response]);
    }

    // add a sleep between calls to avoid hitting the rate limit
    Utilities.sleep(1000);
  }

  // refresh the Google Spreadsheet
  SpreadsheetApp.flush();
}

Also read Create Trello Cards from a Google Form with Google Scripts Easy Guide!



from thetechxp https://ift.tt/oB975uA
via IFTTT

Comments

Popular posts from this blog

किस महानगर में मिल रहा सबसे सस्ता पेट्रोल? जानें तेल का नया भाव https://ift.tt/zKAj5k6

रोज की तरह आज यानि 9 दिसंबर को भी तेल के नए रेट जारी कर दिए गए हैं. जिसके अनुसार, पेट्रोल-डीजल की कीमतों में कोई बदलाव नहीं किया गया है. सभी राज्यों में वाहन ईंधन की कीमतें जस की तस हैं. आइये जानते हैं, किस महानगर में सबसे कम कीमत पर पेट्रोल मिल रहा है और देश के किस इलाके में सबसे सस्ता और सबसे महंगा पेट्रोल मिल रहा है. from आज तक https://ift.tt/o9nAWyY via IFTTT

Best Website For Finding Government Jobs

  Online Sarkari Job Find   is a reliable and comprehensive online platform dedicated to providing the latest information on job opportunities. Our mission is to assist job seekers in finding their ideal positions by offering timely alerts and notifications on the latest job openings, Sarkari Results, Sarkari Exams, Sarkari jobs, Sarkari networks, and Sarkari Naukri. Our team of dedicated professionals is committed to keeping you informed about the most recent developments in the employment sector. With our user-friendly interface and up-to-date content, we strive to ensure that you have access to accurate and reliable information regarding various government job vacancies. Website Link -  Online Sarkari Job Find

IPL: कप्तान बाहर, दिग्गज भी निकले... रिटेंशन ने कैसे बदल दिया टीमों का गणित https://ift.tt/L7Adk8F

आईपीएल के अगले सीजन के लिए 23 दिसंबर को कोच्चि में मिनी ऑक्शन का आयोजन होना है. इस नीलामी से पहले सभी 10 टीमों की ओर से रिटेंशन लिस्ट जारी कर दी गई. from आज तक https://ift.tt/LK4D2kX via IFTTT