public ActionResult Index(URL url) { if (ModelState.IsValid) { /* * The Google URL shortener API is a public API which means we don’t need * to worry about authentication we can access it directly using a public API key. * We now have a URLshortenerService we can use to access the api. */ UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = ConfigurationManager.AppSettings["urlShortenerAPIKey"], ApplicationName = "Get Shorty" }); var m = new Google.Apis.Urlshortener.v1.Data.Url(); m.LongUrl = url.UrlString; ViewBag.Shorty = service.Url.Insert(m).Execute().Id; return(View("Url")); } else { return(View("Index", url)); } }
public string ShortenIt(string url) { var m = new Google.Apis.Urlshortener.v1.Data.Url(); m.LongUrl = url; return(service.Url.Insert(m).Execute().Id); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log) { // parse query parameter string url = req.GetQueryNameValuePairs() .FirstOrDefault(q => string.Compare(q.Key, "url", true) == 0) .Value; // Get request body dynamic data = await req.Content.ReadAsAsync <object>(); // Set name to query string or body data url = url ?? data?.url; log.Info($"Url: {url}"); UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = ConfigurationManager.AppSettings["GoogleAPIKey"], ApplicationName = "URL shortener", }); var m = new Google.Apis.Urlshortener.v1.Data.Url { LongUrl = url }; return(url == null ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a url on the query string or in the request body") : req.CreateResponse(HttpStatusCode.OK, service.Url.Insert(m).Execute().Id)); }
public async Task <string> ShortenUrl(string longUrl) { var url = new Google.Apis.Urlshortener.v1.Data.Url { LongUrl = longUrl }; return((await _urlShortenerService.Url.Insert(url).ExecuteAsync())?.Id); }
private static void googleStuff(string url) { UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = "AIzaSyCetMcIe3VOy0skeuJbWSZZ5M-BKyTkUk4", ApplicationName = "SharpDictionary", }); var m = new Google.Apis.Urlshortener.v1.Data.Url(); m.LongUrl = url; publicUrl = m; response = service.Url.Insert(m).Execute().Id; }
//private const string googleAPIKey = "AIzaSyBIkkmagfceBNyRo7wW3dCOTMk03ycjYJY"; public static string shortenIt(string url) { UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = "AIzaSyBIkkmagfceBNyRo7wW3dCOTMk03ycjYJY", ApplicationName = "Daimto URL shortener Sample", }); var m = new Google.Apis.Urlshortener.v1.Data.Url(); m.LongUrl = url; return(service.Url.Insert(m).Execute().Id); }
public static string GetShortUrl(string longUrl) { UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = "AIzaSyByVwLFuOW52I7RH3MAD--Q0uhbg-KktMM" }); var m = new Google.Apis.Urlshortener.v1.Data.Url(); m.LongUrl = longUrl; return(service.Url.Insert(m).Execute().Id); }
public static string shortenIt(string url) { UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = "AIzaSyBrqWxYLlP4Kx1x__ZngFoEyHC4m-vZg5c", ApplicationName = "Tung Xuan", }); var m = new Google.Apis.Urlshortener.v1.Data.Url(); m.LongUrl = url; return(service.Url.Insert(m).Execute().Id); }
public string shortenIt() { UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = " AIzaSyAx-OPO93_1Jk7w5stGQ7dU82K4jWoq2Fo ", ApplicationName = "VSfirstapp", }); var m = new Google.Apis.Urlshortener.v1.Data.Url(); m.LongUrl = longLink; return(service.Url.Insert(m).Execute().Id); }
public static string shortenIt(string url) { UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = "AIzaSyDz5uUicjUP1ytTBtQE9g3Nw1UYRx0YkNM", ApplicationName = "HuellaCarbono", }); var m = new Google.Apis.Urlshortener.v1.Data.Url(); m.LongUrl = url; return(service.Url.Insert(m).Execute().Id); }
// A request needs to be sent to the Google URL Shortener API containing // longURL so that the shortened version of it can be returned public static string ShortenURL(string longURL) { // Parse the Google API Key from apiKey.json var apiKey = APIKey.GetAPIKey("apikey"); // UrlshortenerService with the parsed API Key service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = apiKey, ApplicationName = "Google URL Shortener Desktop" }); // Request containing the longURL var req = new Google.Apis.Urlshortener.v1.Data.Url(); req.LongUrl = longURL; // Insert the request to the API and return the short URL try { shortURL = service.Url.Insert(req).Execute().Id; } catch (GoogleApiException e) { // Don't show a second APIKeyWindow if one is already open from // the System.IO.FileNotFoundException in APIKey.cs if (Utils.IsWindowOpen <APIKeyWindow>("Google API Key")) { MessageBox.Show("Your Google API Key is incorrect. Please enter " + "it again.", e.GetType().ToString()); new APIKeyWindow().Show(); Utils.CloseWindow("Google URL Shortener"); } } return(shortURL); }
/// <summary>Creates a new short URL.</summary> /// <param name="body">The body of the request.</param> public virtual InsertRequest Insert(Google.Apis.Urlshortener.v1.Data.Url body) { return(new InsertRequest(service, body)); }