YouTube API CFC
Yesterday one of my clients (roundpeg) asked for a ColdFusion interface to the YouTube API. This turned out to be rather simple since they made use of a REST API. From this work I was able to build a CFC to work with all the functions defined in the API. This lets you get video information, profile information, search for videos etc. Best of all - roundpeg, Inc was cool with me releasing the code. You can download the CFC below.
Now the bad news is that YouTube will eventually be switching to a GData based API. I am not a fan of Google's APIs so frankly I can't see this as being a good thing - but I'll worry about that when the API is updated.
Here are some sample calls:
<cfset devid = "changethis">
<cfset yt = createObject("component", "youtube").init(devid)>
<!--- get videos by user --->
<cfdump var="#yt.getVideosByUser('joerinehart')#" label="Videos by user.">
<!--- get music videos tagged Lush --->
<cfdump var="#yt.getVideosByCategoryAndTag(10,'Lush')#" label="Lush music videos." top="10">
p.s. Note that you need to get a developer profile and key before you use the code.
Comments
Another simple question... using the getVideosByTag function, how would I get the total # of records returned so I could set up "paging" links? It seems that I need to have a default perpage value. Without the total # of records returned based on my search term, I cannot create the paging links.
FYI, I have a very cool demo I'll be blogging soon. Mixes CF8+YouTube.cfc together.
"Each youtube.videos.list_by_tag response includes the
video_list.total element, which contains the total
number of records."
I can't figure out what I need to do using your CFC to view the total number of records. Am I missing something? Could you help?
BTW, either go buy Bioshock or add to your wishlist. It's amazing.
Ok the code is done. I'll be uploading to RIAForge in 5 minutes.
I am trying to use your cfc to upload videos to youtube but got some errors.
The cfhttp statement on youtube.cfc line 484 is not returning anything. When I do a cfdump, I see an empty authtoken. Could you please help?
<cfset devid = "AI39si4J8K77YGl7yRXabWq9CFb0M-86TcuYFcYlEmnMDv4XL3OtoK7q1N4ApXYC5Y5ntbFurXGCmGi_U8mRy-CdUHezoMLIXQ">
<cfset yt = createObject("component", "youtube")>
<cfset yt.setDeveloperKey("#devid#")>
<cfset yt.login("myUserName", "myPassword")>
<cfset r = yt.upload('video.wmv','Test Upload','Playing with youtube','Music','testing,fun')>
This returns no error. When I do the following:
<cfdump var="#yt.getVideosByUser('myUserName')#" label="Videos by user.">
The cfdump returns nothing. Do you think this is still caused by the same problem?
Any word on the hotfix for CF7/CF8 from Adobe?
Also, what is the best way to go about tweaking the YouTube CFC for CF7 usage?
"The APIs accessed by this developer ID program have been deprecated and are no longer supported. To use the new APIs or get information about migrating your applications, please visit the YouTube Developer site at code.google.com."
Does that impact YouTube CFC?
@Jason - 2: It should be CF7 compat. The hot fix they are releasing will be for CF7 as well. If I did use any CF8 functionality, it was probably by accident and a small snippet like X++, which would need to change to x=x+1.
@Jason - 3: This was all tested with the new API.


Thanks for saving me the time!