Muschamp Rd

Searching YouTube with PHP

February 17th, 2013
PHP logo

During my most recent period of unemployment, I’ve 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 most importantly maintained some code I used to make web mashups, but other people could use for their own evil purposes.

One method I wrote searches 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 keep trying to get a paying job.

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.

My web mashup code uses a lot of APIs and to use some of them you have to jump through a lot of hoops. Amazon alone has made several changes and demands in the last few years. Rotten Tomatoes changed their API suddenly, Topsy wants to charge for using their API now, I’ve encountered plenty of bugs when using PHP to access, so I was reluctant to integrate either Zend or Google’s beta PHP code. Zend requires “PHP 5.2.11 or later” and Google requires you to register your app/domain (which I did) but worse seems to want you to set up a session connected to a database or a memcache just to search for YouTube videos.

I mainly search YouTube for movie trailers and song performances to go with my quotations. Installing and setting up an entire library of code seems a bit much when I just want to perform a quick search. Google is now working on Version 3.0 of their API. The original version, which my code used to use seems to have been completely retired, but my code now uses version 2.0 which is what the Zend framework uses. I can’t be the only one who wants a lighter weight PHP function to search YouTube.

Posts on Muskblog © Andrew "Muskie" McKay comments not necessarily so...
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.