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>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson