YouTube Offensive Channel Cleaner

215 views
Skip to first unread message

Dmytro Tonkikh

unread,
Aug 14, 2017, 5:51:41 AM8/14/17
to AdWords Scripts Forum
Hello every one!

After AdWords Script Workshop in Hamburg, I decided to share script, which helps me clean all children YouTube Channel. 
Because in CIS countries parents show on their device a lot of different cartoons maybe this problem is eveywhere.
But with this script you can also setup to exclude channels with offensive videos (ISIS, Politician Propaganda, etc).


Script finds bad tags in youtube videos and then add channels to shared negative placement list.
It work 24/7 and takes only new videos where you ads was showing for last hour.

To find bad tags I've created another script

/******************************************
* YouTube Tags Finder 
*
* Created by: Dmytro Tonkikh
******************************************/


function main() {
  // Setup Google Sheet. Spreadsheet must have 2 sheets - Keywords and Results.
  
  var ss = SpreadsheetApp.openByUrl(spreadsheetUrl); 
  var keywordsSheet = ss.getSheetByName('Keywords');
  var resultsSheet = ss.getSheetByName('Results');
  var lastRow = keywordsSheet.getLastRow();
  resultsSheet.clear(); //Clean all previous results from sheet
  var range = keywordsSheet.getRange(1, 1, lastRow, 1);
  
  //Fetch all keywords from first column
  
  var values = range.getValues();
  Logger.log(values.length);
  
  var tags = [];
  var videos = [];
  
  for(var i = 0; values.length > i; i++) {
    
    var query = values[i][0];
    var results = YouTube.Search.list('id,snippet',
                                      {q: query, 
                                       maxResults: 50, 
                                       regionCode: "US",  
                                       relevanceLanguage: "en-US"}); 
    for (var j in results.items) {
      var item = results.items[j];
      videos.push(item.id.videoId);
    }
  }
  
  
  for (var i in videos) {
   try { 
     
    var results = YouTube.Videos.list('snippet', {id : videos[i]});
      if (results.items[0].snippet !== undefined) {
        var tagsArray = results.items[0].snippet.tags;
        if (tagsArray !== undefined) {    
          for (var k in tagsArray) { 
            tags.push([tagsArray[k]])
          }
        }
      }
    } catch (e) {
      Logger.log(e);
    }
  
  }
  
  //Write results
  resultsSheet.getRange(1, 1, tags.length, 1).setValues(tags); 
}


Please enable YouTube on Advanced API and in the developers console.

Change regionCode and relevanceLanguage depends on your region.

Also copy public spreadsheet  and change spreadsheetUrl in the script code.

Anthony Madrigal

unread,
Aug 14, 2017, 9:23:55 AM8/14/17
to AdWords Scripts Forum
Hi Dmytro,

Glad you were able to put the skills from the workshop to good use. This script looks great!

Cheers,
Anthony
AdWords Scripts Team

Lucas Dal Pont

unread,
Dec 29, 2022, 12:31:38 AM12/29/22
to Google Ads Scripts Forum
Hi everyone. This script is not working anymore. As I done know much about coding, is it possible you give me some help fixing this code to the present google fields?

Thanks so much
Lucas

Google Ads Scripts Forum Advisor

unread,
Dec 29, 2022, 5:03:18 AM12/29/22
to adwords...@googlegroups.com

Hi Lucas,

 

Ciara here, from the Google Ads Scripts team. Thank you for reaching out.

 

Upon checking the script YouTube Channels Cleaner, linked below, it appears that it is not migrated to the new script experience. The new script experience is now based on Google Ads API infrastructure which mainly supports GAQL. Just an example, the query SELECT Url FROM URL_PERFORMANCE_REPORT WHERE CampaignName CONTAINS "(Video)" DURING TODAY should now be SELECT detail_placement_view.target_url FROM detail_placement_view WHERE campaign.name REGEXP_MATCH ".*(put filter here).*" AND segments.date DURING TODAY in the new script environment.

 

You can use these documentations below in migrating the said scripts to the New Script experience:

 

Moving forward, the second script, Youtube Tag finder, can you provide more context with regards to the error you encountered with the said script? In addition, kindly provide us with your Google Ads CID, the script name of your script on the account, screenshots that shows the error on your end, and a shareable link (guide) of the spreadsheet you are using so we can further investigate.

 

You may send privately via the reply to author option. If this option is not available on your end, you may send it through our email (googleadsscr...@google.com) instead.

 

Regards,

Google Logo
Ciara
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2hOzwX:ref
Reply all
Reply to author
Forward
0 new messages