0

SO. I have the following URL from a third party accessed with an API call.

https://scontent.xx.fbcdn.net/v/t1.0-9/15665479_1260320054027269_4201232212927955955_n.jpg?oh=ee01f2ec47b2e972bc12f99d988db241&oe=5946A159

I'd like to shorten this URL with Google shortener from inside my action method, how should i do this?

Note: The goo.gl shortner nuget package installed.

Dawar
  • 99
  • 3
  • 14

1 Answers1

3
class Program
{ 
    static void Main(string[] args)
    {

       UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer()
        {
            ApiKey = "API KEY from Google developer console",
            ApplicationName = "Daimto URL shortener Sample",
        });

        var m = new Google.Apis.Urlshortener.v1.Data.Url();
        m.LongUrl = @"https://scontent.xx.fbcdn.net/v/t1.0-9/15665479_1260320054027269_4201232212927955955_n.jpg?oh=ee01f2ec47b2e972bc12f99d988db241&oe=5946A159";
        var shortenedUrl =  service.Url.Insert(m).Execute().Id;

        Console.WriteLine(shortenedUrl);
        Console.ReadKey();
    }

}
Zbidi
  • 116
  • 10
  • Whatta humble and generous person you are. while others vote to close my question you wrote an answer that worth thousands to me. Be the same after your reputation goes high people now a days are too arrogant. Thank you for to the point answer... – Dawar Feb 27 '17 at 13:21
  • 1
    if it works for you, you might want to accept the answer. – Zbidi Feb 27 '17 at 13:22
  • Already did it... Thank you too much. – Dawar Feb 27 '17 at 13:23
  • It takes a few second likes 2 or 3 is that normal? – Dawar Feb 27 '17 at 13:27
  • And Can I do bulk insert like ten URLs at a time? – Dawar Feb 27 '17 at 13:27
  • yeah for me it also takes likes 2-3 seconds. couldnt find a bulk method. may be you can try implmeneting service.url.insert in a method, and you can call it accordingly within a loop. – Zbidi Feb 27 '17 at 13:31
  • goo.gl is discontinued now i believe. – user2404597 Dec 09 '18 at 21:57