aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Create Goog.le Short Urls in JavaScript using Google URL Shortener API Example

Feb 20, 2013

Here I will explain how to create JavaScript short urls using google URL Shortener API in jQuery or create goog.le short urls using jQuery, JavaScript. Google Provides URL Shortener API to create short urls with goog.le for free with a daily limit of 1,000,000 requests.


In previous articles I explained Show user current location on google map, Google Map with latitude and longitude, jQuery Google currency converter and many articles relating to Google API, JavaScript, jQuery, Now I will explain how to create short urls using google URL Shortener API in JavaScript , jQuery.

To create short urls using Google api first we need to get API key from Google for that check this article Get Google API key once you get the api key click on Services >> Enable URL Shortner API then write the following code

<title>URL Shortener using Google API. </title>
<script src="" type="text/javascript"> </script>
<script type="text/javascript">
function makeRequest() {
var Url = document.getElementById("longurl").value;
var request = gapi.client.urlshortener.url.insert({
'resource': {
'longUrl': Url
request.execute(function(response) {

if ( != null) {
str = "<b>Long URL:</b>" + Url + "<br>";
str += "<b>Test Short URL:</b> <a href='" + + "'>" + + "</a><br>";
document.getElementById("result").innerHTML = str;
else {
alert("Error: creating short url \n" + response.error);
function load() {
gapi.client.load('urlshortener', 'v1', function() { document.getElementById("result").innerHTML = ""; });
window.onload = load;
<h2> URL Shortener using Google API. </h2>
<td>Enter Long URL:</td>
<input type="text" id="longurl" name="url" size="30" value="" />
<td><input type="button" value="Create Short Url" onclick="makeRequest();" /></td>
<td colspan="2">
<div id="result"></div>
If you observe above code in script section I written gapi.client.setApiKey('AIzaSyDV5_Ca9cEVSFaiLkyzGIcDcbnV_4CiA0o'); here you need to replace with your API Key.


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...

how to shorten url in addressbar through google api

Anonymous said...

how to get bank details from bank ifsc code in textbox

Anonymous said...

how to get city,area from pin code in textbox

Anonymous said...

how can we get the api key

joe said...

if i used the same APIkey any problem occur???

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.