hungvb

[C#] How to shorten link with bitly Winform

Nov 2nd, 2021
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using BitlyAPI;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Diagnostics;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12.  
  13. namespace ShortenLinkBitly
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private async void btnCreate_Click(object sender, EventArgs e)
  23.         {
  24.             var bitly = new Bitly("19ae7ac3e2912e4b688eafd1848e308cb20f082c"); // your accss token
  25.             var linkResponse = await bitly.PostShorten(txt_long_link.Text.Trim());
  26.             var newLink = linkResponse.Link;
  27.             lbl_short_link.Text = newLink;
  28.         }
  29.  
  30.         private void btn_copy_Click(object sender, EventArgs e)
  31.         {
  32.             Clipboard.SetText(lbl_short_link.Text);
  33.         }
  34.  
  35.         private void lbl_short_link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  36.         {
  37.             Process.Start(lbl_short_link.Text);
  38.         }
  39.     }
  40. }
  41.  
Add Comment
Please, Sign In to add comment