Since Youtube shut down its RSS feeds for searches with it's newest version of the API, I've been trying to recreate them using Google App Script. Here's what I have so far (based off of this tutorial for converting a twitter widget to RSS):
function getSearches(a){
try{
var rss,title,link;
title="Youtube RSS Feed";
link="http://www.youtube.com";
var d=ScriptApp.getService().getUrl()+"?"+a;
rss='<?xml version="1.0"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
rss+='<channel><title>'+title+'</title>';
rss+='<link>'+link+'</link>';
rss+='<atom:link href="'+d+'" rel="self" type="application/rss+xml" />';
rss+='<description>Youtube RSS feed updated on '+new Date()+'.</description>';
var results = YouTube.Search.list('id, snippet', {
q: a,
maxResults: 50,
order: 'date'
});
for(var i = 0; i < results.items.length; i++){
var item = results.items[i];
rss += "<item>";
rss += "<title>" + item.snippet.title + "</title>";
rss += "<link>http://www.youtube.com/watch?v=" + item.id.videoId + "</link>";
rss += "<description>" + item.snippet.description + "</description>";
rss += "<pubDate>" + Utilities.formatDate(new Date(item.snippet.publishedAt), "EDT", "EEE, dd MMM yyyy HH:mm:ss Z") + "</pubDate>";
rss += "<guid>http://www.youtube.com/watch?v=" + item.id.videoId + "</guid>";
rss += "</item>";
}
rss+="</channel></rss>";
Logger.log(rss)
return rss
}
catch(e){
return"Something went wrong. Please retry after few minutes"
}
}
function doGet(e){
//var a = e.queryString();
var a = getSearches("search term");
return ContentService.createTextOutput(a).setMimeType(ContentService.MimeType.RSS);
}
When I publish this as a web app and test it, the resulting page looks good. I can click the links and they take me to the correct videos. However when I try to subscribe to the feed (using Inoreader in my case), it says that there is no feed found. If I subscribe to the web app url directly in my reader (again, Inoreader), it appears to work; but all of the entries link to the web app, not youtube, and return an error from Google App Script when clicked.
Ideally I want the web app to be able to take an any search term and return the feeds to subscribe to via https://script.google.com/macros/s/LONG_KEY/exec?SEARCH_TERM similar to how the twitter RSS linked above functions. Has anyone had any success with something like this or can give me pointers?
Deploy as Webappdown the bottom there is a section sayingWho has access to the appI often will have another browser running which I have not logged into google to do my testing, so that I know that the access levels are correct. Apart from that if your feed is identical it should just work. - FuzzyJulz