Muschamp Rd

Searching YouTube with PHP

February 17th, 2013
PHP logo

This was one of the cooler features I implemented in my mashup codebase. Alas Google went and changed YouTube’s API. I quickly tried to fix it, but when I could not and no one on Stack Overflow could help the problem got set aside while I focussed on passing all three CFA® exams.

While I was unemployed I tried to brush up on some of my skills, perversely one thing I’ve spent a lot of time doing is writing PHP. I’m not a big fan of PHP but I seem to have written and give away a lot of code, but after all these years I wouldn’t rush out and download it. It badly needs updating.

One method I wrote searched YouTube for a passed in string and returns the HTML code for the top video matching that string or NULL. I was originally going to search other APIs for video clips but never got around to implementing that feature.

I don’t think anyone is using all of my code to do anything interesting but referral logs indicate people are looking at the code. I think my code for accessing the Amazon Product API and some code I wrote that uses SimplePie may be the most popular but this simple function for searching YouTube seems like it would be useful. The official Google Data API is quite daunting and there are multiple more official ways to do things, but behold mine:

Damn Pastebin embed code doesn’t always work. Here is a link to the code snippet.

APIs keep changing and sometimes they restrict your access or throttle you. I was mainly searching YouTube for movie trailers and song performances to go with my quotations. For posterity here is the Stack Overflow thread I started, but after all this time I’d Google and see if someone has implemented this. If you have thoughts on YouTube, PHP, or APIs you can leave them below.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Posts on Muskblog © Andrew "Muskie" McKay.
CFA Institute does not endorse, promote or warrant the accuracy or quality of Muskblog. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.