using Google Url Shortner API in C#

Here the way you can use it


1. install following nuget packages in project

Google.Apis.Urlshortener.v1. Data

2. Get the API key from following link and paste in “Your API Key”

using System;
using Google.Apis.Urlshortener.v1;
using Google.Apis.Urlshortener.v1.Data;
using Google.Apis.Services;

namespace shortenURLwithGoogleAPIService
 class Program
 private const string ApiKey = "Your API Key";

static void Main(string[] args)
 var initializer = new BaseClientService.Initializer
 ApiKey = ApiKey, 
 var service = new UrlshortenerService(initializer);
 var longUrl = "your long url";
 var response = service.Url.Insert(new Url { LongUrl = longUrl }).Execute();

Console.WriteLine($"Short URL: {response.Id}");



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s