CFLib.org – Common Function Library Project

googleURLExpand(url)

Last updated January 13, 2011

author

Raymond Camden

Version: 1 | Requires: CF8 | Library: UtilityLib

Description:
Reverses a URL shortened by Google's URL Shortening service.

Return Values:
Returns a string.

Example:

<cfset sampleURL = "http://www.coldfusionjedi.com/index.cfm/2011/1/10/jQuery-based-example-of-simple-shopping-cart-UI">
<cfset test = googleURLShorten(sampleURL)>
<cfoutput>
I shorteneded #sampleURL# to #test#.<br/>
</cfoutput>

<cfset reversed = googleURLExpand(test)>
<cfoutput>
I expanded it to #reversed#.
</cfoutput>

Parameters:

Name Description Required
url Shortened URL to expand. Yes

Full UDF Source:

<!---
 Reverses a URL shortened by Google's URL Shortening service.
 
 @param url 	 Shortened URL to expand. (Required)
 @return Returns a string. 
 @author Raymond Camden (ray@camdenfamily.com) 
 @version 1, January 13, 2011 
--->
<cffunction name="googleURLExpand" output="false" returnType="string">
	<cfargument name="url" type="string" required="true">
	<cfset var httpResult = "">
	<cfset var result = "">

	<cfhttp url="https://www.googleapis.com/urlshortener/v1/url?shortUrl=#urlEncodedFormat(arguments.url)#" method="get" result="httpResult"></cfhttp>

	<cfset result = httpResult.filecontent.toString()>
	<cfreturn deserializeJSON(result).longUrl>
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson