2017-02-27 49 views
-1

SO。我從通過API調用訪問的第三方獲取以下網址。如何使用asp.net mvc以編程方式縮短與谷歌縮短器的URL?

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

我想從我的行動方法中縮短這個網址與谷歌縮短,我應該怎麼做?

注意:安裝了goo.gl shortner nuget軟件包。

回答

1
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_42_n.jpg?oh=ee01f2ec47b2e972bc12f99d988db241&oe=5946A159"; 
     var shortenedUrl = service.Url.Insert(m).Execute().Id; 

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

} 
+0

你是謙虛而慷慨的人。而其他人投票結束我的問題,你寫了一個價值數千美元的答案。在你聲譽高漲的時候,同樣如此,一天過於傲慢。謝謝你的回答... – Dawar

+1

如果它適合你,你可能想接受答案。 – Zbidi

+0

已經做到了...非常感謝。 – Dawar