Accessibility

TechNote

Hot Fix for Google and YouTube API (ColdFusion 7 and 8)

Issue


Google offers developers an API to allow you to work with all the different Google services, including the video service from YouTube. Recent changes to the API allows you to authenticate and interact with all their services. To support these changes, Adobe ColdFusion added a new attribute called multiparttype to the cfhttp tag.

Note: This TechNote is not meant as documentation for using the Google API. You can find complete API documentation on Google's web site.

Reason


The cfhttp tag allows for multipart format data with the multipart attribute in cfhttp or by using a header with content type. The issue is that cfhttp tag only uses multipart/form-data while Google and YouTube requires multipart/related. The attached hot fix adds this functionality.

Solution


Install the ColdFusion Hot Fix
  1. Download and unzip the version of the hot fix you require
  2. Open the ColdFusion MX Administrator and select the System Information page. Next to the Update File field, either:
    • Type in the file path to the hf###-72973.jar file and click Submit.
      Or
    • Select the Browse Button and browse to hf###-72973.jar. Select the file and click apply.
  3. Stop each ColdFusion server you wish to update
  4. Since we have updated the tag attributes we need a new tag definition library
    • Go to each server's ..\WEB-INF\cftags\META-INF directory.
    • Backup the existing taglib.cftld file.
    • Once backed up replace the taglib.cftld with the one you just downloaded.

Restart each server updated. The ColdFusion MX hot fix JAR file does not need to be retained after installing it with the ColdFusion Administrator. The file has been copied into the correct location. The hot fix JAR file will appear as a new entry in the System Information list.

Sample ColdFusion Code

The sample code below shows how to authenticate, create the required Atom XML, and upload a video. Upon completion you should see a '201 Created' http code.

All CAPS are the areas that require your Google account and video file data for testing.

 <!--- **********************************
		
Settings to control request
*********************************** --->
<cfsetting requesttimeout="450">
<cfset videoName = "FULL PATH TO VIDEO">
<cfset videoFileName = "JUST THE FILE NAME OF VIDEO FILE">
<!--- Google Keys per user account --->
<cfset username = "GOOGLEACCOUNTNAME">
<cfset password = "GOOGLEACCOUNTPASSWORD""/>
<cfset clientKey = "GOOGLECLIENTKEY"/>
<cfset devKey = "GOOGLEDEVKEY"/> <!--- **********************************
End of Settings - No changes required below this line to test this tag.
*********************************** ---> <!--- **********************************
Authenticate with Google
*********************************** --->
<cfoutput>
<cfhttp url=https://www.google.com/accounts/ClientLogin method="post" result="result" charset="utf-8">
<cfhttpparam type="formfield" name="accountType" value="HOSTED_OR_GOOGLE">
<cfhttpparam type="formfield" name="Email" value="#username#">
<cfhttpparam type="formfield" name="Passwd" value="#password#">
<cfhttpparam type="formfield" name="service" value="youtube">
<cfhttpparam type="formfield" name="source" value="collins">
</cfhttp> <cfset content = result.filecontent>
<cfset authdata = structNew()>
<cfloop index="line" list="#content#" delimiters="#chr(10)#">
<cfset dtype = listFirst(line, "=")>
<cfset value = listRest(line, "=")>
<cfset authdata[dtype] = value>
</cfloop>
<!--- **********************************
End Authenticatation
*********************************** ---> <!--- **********************************
Create ATOM XML to pass to YouTube
*********************************** --->
<cfsavecontent variable="meta">
<cfoutput>
<?xml version="1.0"?>
<entry xmlns=http://www.w3.org/2005/Atom
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">Test Upload</media:title>
<media:description type="plain">Test Description</media:description>
<media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Autos</media:category>
<media:keywords>Geschke</media:keywords>
</media:group>
</entry>
</cfoutput>
</cfsavecontent>
<!--- Write XML to file to be used with upload cfhttp --->
<cffile action="write" ./meta.xml")#" output="#trim(meta)#" />
<!--- **********************************
Send Video and ATOM XML to Google using multipart\related
*********************************** --->
<cfset youTubeUploadURL = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"/>
<cfhttp url="#youTubeUploadURL#" result="result" method="POST" timeout="450" multiparttype="related">
<cfhttpparam type="header" name="Authorization" value="GoogleLogin auth=#authdata.auth#">
<cfhttpparam type="header" name="X-GData-Client" value="#variables.clientkey#">
<cfhttpparam type="header" name="X-GData-Key" value="key=#variables.devkey#">
<cfhttpparam type="header" name="Slug" value="#videoFileName#">
<cfhttpparam type="file" name="API_XML_Request"
./meta.xml")#" mimetype="application/atom+xml">
<cfhttpparam type="file" name="file" mimetype="video/quicktime">
</cfhttp> <!--- View Result --->
<cfdump var="#result#"/></cfoutput>

Additional Information


Troubleshooting
If you see an"Attribute validation error for the http tag" error ,you have not installed the new tag lib definitions to the ColdFusion server. Other ColdFusion Hot Fix TechNotes

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:kb406660

Products Affected:

coldfusion