I first tried
class Youtube
def search_url(term)
url = "https://gdata.youtube.com/feeds/api/videos"
url += "?q=#{term}&alt=json&restriction=US&max-results=50&orderby=viewCount"
url += "&fields=entry(id,title,yt:noembed,media:group(media:description),author(name),yt:statistics(@viewCount))"
url += "&key=#{DEV_KEY}"
But it wasn't able to handle queries like "Macklemore & Ryan Lewis"
Then someone suggested
require 'cgi'
class Youtube
def search_url(term)
term = CGI.escape(term)
url = "https://gdata.youtube.com/feeds/api/videos"
url += "?q=#{term}&alt=json&restriction=US&max-results=50&orderby=viewCount"
url += "&fields=entry(id,title,yt:noembed,media:group(media:description),author(name),yt:statistics(@viewCount))"
url += "&key=#{DEV_KEY}"
But it didn't solve the problem. But it just made queries that worked before not work anymore.
Opening these two links in Firefox (other browsers don't seem to be able to open them)
https://gdata.youtube.com/feeds/api/videos?q=Macklemore+%26+Ryan+Lewis&restriction=US&max-results=50&orderby=viewCount https://gdata.youtube.com/feeds/api/videos?q=Macklemore & Ryan Lewis&restriction=US&max-results=50&orderby=viewCount
tells me that "&" in the query really affects badly.
How can this be really solved?