Formatting url to generate goo.gl short url

1k Views Asked by At

How do a form a url to generate a goo.gl short url?

In bit.ly can do this with:

http://api.bit.ly/shorten?t=1&version=2.0.1&login=bitlyspreadsheets&apiKey=(api_key)&format=text&longUrl=http://www.google.com

Working off the documentation for goo.gl API

The normal request form is this:

POST https://www.googleapis.com/urlshortener/v1/url Content-Type: application/json

{"longUrl": "URL"}

How do I convert this to a url?

1

There are 1 best solutions below

2
On

I used Fiddler to do the POST as you described, with the URL of this question, like this:

POST /urlshortener/v1/url HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: www.googleapis.com
Content-Length: 102

{"longUrl" : "http://stackoverflow.com/questions/5683562/formatting-url-to-generate-goo-gl-short-url"}

and the response I got was,

HTTP/1.1 200 OK
ETag: "7EqIPxWjdFEMGopn0m-wh5UjU2M/mbXotpNse1SbcCFgA5pLLsB6hi4"
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Sat, 16 Apr 2011 01:13:41 GMT
Content-Type: application/json; charset=UTF-8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Content-Length: 164

{
 "kind": "urlshortener#url",
 "id": "http://goo.gl/Ztc9b",
 "longUrl": "http://stackoverflow.com/questions/5683562/formatting-url-to-generate-goo-gl-short-url"
}

That would be a JSON representation that contains your shortened URL.