This component is very, very simple to use.

You need to add GoogleAPI.UrlShortener reference for your application.

For shorten URLs, you can doing something as:

            UrlResource client = new UrlResource();

            // Shorten url according the parameter below.
            var response = client.Insert(
                new ShortenRequest { LongUrl = "http://gshortener.codeplex.com" });

            // Print short url. Ex: http://goo.gl/sOme
            Console.WriteLine(response.Id);

            // Print long url. Ex: http://gshortener.codeplex.com
            Console.WriteLine(response.LongUrl);

 For get informations about a Short Url, follow this example:

            UrlResource client = new UrlResource();

            // Shorten url according the parameter below.
            var response = client.Get("http://goo.gl/bh6FT");

            // Print status. Ex: "OK"
            Console.WriteLine(response.Status);

            // Print long url. Ex: http://www.google.com
            Console.WriteLine(response.LongUrl);

 For get analytics informations about a Short Url, follow this example:

            UrlResource client = new UrlResource();

            // Shorten url according the parameter below.
            var response = client.GetWithProjection("http://goo.gl/bh6FT", "FULL");


            // Print Short Url Clicks Quantity.
            Console.WriteLine(response.Analytics.AllTime.ShortUrlClicks);

            // Print the country with most clicks on all time.
            Console.WriteLine("Country {0}, Clicks Quantity {1}",
                response.Analytics.AllTime.Countries.First().Id,
                response.Analytics.AllTime.Countries.First().Count);

            // Print the browsers with less clicks on day.
            Console.WriteLine("Country {0}, Clicks Quantity {1}",
                response.Analytics.Day.Browsers.Last().Id,
                response.Analytics.Day.Browsers.Last().Count);

All methods and properties was implemented. For complete reference, go to

http://code.google.com/apis/urlshortener/v1/reference.html

OBSERVATION: for List method (history of a determined user on Google Url Shortener Services) you need to be AUTHENTICATED by Google. More information here.

OBSERVATION 2: this component is a WCF Service Library. If you are testing this in a .NET client you need to copy the app.config to this client.

Last edited Jan 12, 2011 at 5:45 PM by evenancio, version 4

Comments

No comments yet.