Google URL Kısaltıcısı, C#

Google URL Shortener, C#

Merhabalar,

Google’un hizmete sunduğu URL kısaltıcısısı, Goo.gl appspot üzerinden API desteği vermeye başladı. Hatta başlayalı bayağı oldu ama ben genede yeni bir habermiş gibi vereyim :) .

Goo.gl’dan kısaltmak istediğimiz adrese (http://ggl-shortener.appspot.com/?url=http://kaansengul.com) gidip, bize döndürdüğü nesneyi JSON objesi gibi okuyup, JSON.Net kullanarak sonucu basit bir şekilde elde edebiliyoruz:

        private string short(string url)
        {
            try
            {

                WebClient client = new WebClient();
                client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                string jsonText = new StreamReader(client.OpenRead("http://ggl-shortener.appspot.com/?url=" + url)).ReadToEnd();

                Googl gShortUrl = JsonConvert.DeserializeObject(jsonText, typeof(Googl)) as Googl;

                return gShortUrl.short_url;
            }
            catch
            {
                return null;
            }
        }
    }

    public class Googl
    {
        public string short_url { get; set; }
    }

Bu yöntemi kullanarak yaptığım basit WinForms uygulamasına buradan erişebilirsiniz.

Google URL Shortener, C#Projeyi ziyaret et

Yorum yapın

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>