如何使用 asp.net mvc 以编程方式使用 google 缩短器缩短 URL?
How can I shorten a URL with google shortener programmatically using asp.net mvc?
所以。我通过 API 调用从第三方获得了以下 URL。
https://scontent.xx.fbcdn.net/v/t1.0-9/15665479_1260320054027269_4201232212927955955_n.jpg?oh=ee01f2ec47b2e972bc12f99d988db241&oe=5946A159
我想在我的操作方法中用 Google 缩短器缩短这个 URL,我应该怎么做?
注意:已安装 goo.gl 较短的 nuget 包。
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();
}
}
所以。我通过 API 调用从第三方获得了以下 URL。
https://scontent.xx.fbcdn.net/v/t1.0-9/15665479_1260320054027269_4201232212927955955_n.jpg?oh=ee01f2ec47b2e972bc12f99d988db241&oe=5946A159
我想在我的操作方法中用 Google 缩短器缩短这个 URL,我应该怎么做?
注意:已安装 goo.gl 较短的 nuget 包。
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();
}
}