/// <summary> /// Expands a short URL or gets creation time and analytics. /// Documentation https://developers.google.com/urlshortener/v1/reference/url/get /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Urlshortener service.</param> /// <param name="shortUrl">The short URL, including the protocol.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>UrlResponse</returns> public static Url Get(UrlshortenerService service, string shortUrl, UrlGetOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (shortUrl == null) { throw new ArgumentNullException(shortUrl); } // Building the initial request. var request = service.Url.Get(shortUrl); // Applying optional parameters to the request. request = (UrlResource.GetRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Url.Get failed.", ex); } }
public UrlShortenerEndpoint(string apiKey) { _urlShortener = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = apiKey }); }
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)); }
// TODO: Move apiKey to database public virtual async Task SetupAsync(string apiKey) { try { _baseClientService = new BaseClientService.Initializer() { ApplicationName = "Ditto", ApiKey = apiKey }; _urlShortenerService = new UrlshortenerService(_baseClientService); _customSearchService = new CustomsearchService(_baseClientService); await Youtube.SetupAsync(_baseClientService); // Test method var test = await Youtube.GetPlaylistNameAsync("0"); } catch (Exception ex) { if (ex is GoogleApiException) { throw ex; } } }
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 Program() { service = new UrlshortenerService(new BaseClientService.Initializer { ApplicationName = "UrlShortener.ShortenURL sample", }); }
public URLShortenerService() { service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = "AIzaSyBiyJr0H5EgXPbPANyucxIedvrbG4XLYYE", ApplicationName = "CSCASSIGNMENT", }); }
public static async Task <string> UnshortenUrlAsync(string apiKey, string shortUrl) { return((await Task.Run(() => { UrlshortenerService service = urlShortenerService ?? CreateShortenerService(apiKey); return service.Url.Get(shortUrl).ExecuteAsync(); })).LongUrl); }
UrlshortenerService CreateUrlshortenerService() { var service = new UrlshortenerService(new BaseClientService.Initializer { ApiKey = ApiKey }); return(service); }
public static string unShortenIt(string url) { UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = "AIzaSyBIkkmagfceBNyRo7wW3dCOTMk03ycjYJY", ApplicationName = "Daimto URL shortener Sample", }); return(service.Url.Get(url).Execute().LongUrl); }
public ShortenService() { var service = new BotServices(); Shorten = new UrlshortenerService(new BaseClientService.Initializer { ApiKey = service.GetAPIToken("google"), ApplicationName = "FlawBOT" }); }
public string unShortenIt() { UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = " AIzaSyAx-OPO93_1Jk7w5stGQ7dU82K4jWoq2Fo ", ApplicationName = "VSfirstapp", }); return(service.Url.Get(getShortLink()).Execute().LongUrl); }
public static string unShortenIt(string url) { UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer() { ApiKey = "AIzaSyDz5uUicjUP1ytTBtQE9g3Nw1UYRx0YkNM", ApplicationName = "HuellaCarbono", }); return(service.Url.Get(url).Execute().LongUrl); }
protected void Page_Load(object sender, EventArgs e) { // If we did not construct the service so far, do it now. if (_service == null) { _service = new UrlshortenerService(); // You can enter your developer key for services requiring a developer key. /* _service.DeveloperKey = "<Insert Developer Key here>"; */ } }
protected void Page_Load(object sender, EventArgs e) { // If we did not construct the service so far, do it now. if (service == null) { BaseClientService.Initializer initializer = new BaseClientService.Initializer(); // You can enter your developer key for services requiring a developer key. /* initializer.ApiKey = "<Insert Developer Key here>"; */ service = new UrlshortenerService(initializer); } }
public CustomPropertiesController() { service = new UrlshortenerService(new BaseClientService.Initializer { ApplicationName = "UrlShortener.ShortenURL sample", ApiKey = "AIzaSyAMzN-xoUrT15H_0LPJxuwKVV5Sq44acXk" }); _contentService = Services.ContentService; _umbracoHelper = new UmbracoHelper(UmbracoContext.Current); }
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; }
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 void ChangeGoogleApiKey(string GoogleApiKey) { var bcs = new BaseClientService.Initializer { ApplicationName = "Nadeko Bot", ApiKey = GoogleApiKey, }; yt = new YouTubeService(bcs); sh = new UrlshortenerService(bcs); cs = new CustomsearchService(bcs); }
//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 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); }
private static void CreateShortURL(UrlshortenerService service) { // Request input string urlToShorten = "http://maps.google.com/"; CommandLine.RequestUserInput("URL to shorten", ref urlToShorten); CommandLine.WriteLine(); // Shorten URL Url response = service.Url.Insert(new Url { LongUrl = urlToShorten }).Fetch(); // Display response CommandLine.WriteLine(" ^1Short URL: ^9{0}", response.Id); }
public GoogleApiService() { var bcs = new BaseClientService.Initializer { ApplicationName = "Nadeko Bot", ApiKey = NadekoBot.Credentials.GoogleApiKey }; _log = LogManager.GetCurrentClassLogger(); yt = new YouTubeService(bcs); sh = new UrlshortenerService(bcs); }
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); }
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); }
private async Task Run() { UserCredential credential; using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read)) { credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, new[] { UrlshortenerService.Scope.Urlshortener }, "user", CancellationToken.None, new FileDataStore("UrlShortener.Auth.Store")); } // Create the service. var service = new UrlshortenerService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "UrlShortener.ListURLs Sample", }); // List all shortened URLs: Console.WriteLine("Retrieving list of shortened urls..."); int i = 0; string nextPageToken = null; do { // Create and execute the request. var request = service.Url.List(); request.StartToken = nextPageToken; UrlHistory result = await request.ExecuteAsync(); // List all items on this page. if (result.Items != null) { foreach (Url item in result.Items) { Console.WriteLine((++i) + ") URL" + item.Id + " -> " + item.LongUrl); } } // Continue with the next page. nextPageToken = result.NextPageToken; } while (!string.IsNullOrEmpty(nextPageToken)); if (i == 0) { Console.WriteLine("You don't have any shortened URLs! Visit http://goo.gl and create some."); } }
static void Main(string[] args) { // Initialize this sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("URLShortener -- List URLs"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); FullClientCredentials credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); // Create the service. var service = new UrlshortenerService(auth); // List all shortened URLs: CommandLine.WriteAction("Retrieving list of shortened urls..."); int i = 0; string nextPageToken = null; do { // Create and execute the request. var request = service.Url.List(); request.StartToken = nextPageToken; UrlHistory result = request.Fetch(); // List all items on this page. if (result.Items != null) { foreach (Url item in result.Items) { CommandLine.WriteResult((++i) + ".) URL", item.Id + " -> " + item.LongUrl); } } // Continue with the next page nextPageToken = result.NextPageToken; } while (!string.IsNullOrEmpty(nextPageToken)); if (i == 0) { CommandLine.WriteAction("You don't have any shortened URLs! Visit http://goo.gl and create some."); } // ... and we are done. CommandLine.PressAnyKeyToExit(); }
public static async Task <string> ShortenUrlAsync(string apiKey, string longUrl) { return((await Task.Run(() => { UrlshortenerService service = urlShortenerService ?? CreateShortenerService(apiKey); Url original = new Url { LongUrl = longUrl }; return service.Url.Insert(original).ExecuteAsync(); })).Id); }
private static void ResolveShortURL(UrlshortenerService service) { // Request input string urlToResolve = "http://goo.gl/hcEg7"; CommandLine.RequestUserInput("URL to resolve", ref urlToResolve); CommandLine.WriteLine(); // Resolve URL Url response = service.Url.Get(urlToResolve).Fetch(); // Display response CommandLine.WriteLine(" ^1Status: ^9{0}", response.Status); CommandLine.WriteLine(" ^1Long URL: ^9{0}", response.LongUrl); }
public static string GetShortUrl(this string longUrl) { var url = new Url() { LongUrl = longUrl }; var clientService = new BaseClientService.Initializer { ApiKey = ConfigurationManager.AppSettings["GoogleApiKey"] }; var returnValue = new UrlshortenerService(clientService).Url.Insert(url).Execute(); return(returnValue.Id); }
public GoogleApiService(IBotCredentials creds, IHttpClientFactory factory) { _creds = creds; _httpFactory = factory; var bcs = new BaseClientService.Initializer { ApplicationName = "Nadeko Bot", ApiKey = _creds.GoogleApiKey, }; yt = new YouTubeService(bcs); sh = new UrlshortenerService(bcs); cs = new CustomsearchService(bcs); }
/// <summary> /// Main method /// </summary> internal static void Main(string[] args) { // Initialize this sample CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("URL Shortener"); // Create the service var service = new UrlshortenerService(); // Ask the user what he wants to do CommandLine.RequestUserChoice( "What do you want to do?", new UserOption("Create a short URL", () => CreateShortURL(service)), new UserOption("Resolve a short URL", () => ResolveShortURL(service))); CommandLine.PressAnyKeyToExit(); }
public ServiceUrlShortner(UrlshortenerService urlshortenerService) { _urlshortenerService = urlshortenerService; }
private string GetShortUrl(string longUrl) { BaseClientService.Initializer initializer = new BaseClientService.Initializer(); initializer.ApiKey = "AIzaSyCFRjZor7ucfj7XioiP_Hx23A3VVCYVn5M"; UrlshortenerService service = new UrlshortenerService(initializer); Url toInsert = new Url { LongUrl = longUrl }; toInsert = service.Url.Insert(toInsert).Fetch(); return toInsert.Id; }