using Google Url Shortner API in C#

Here the way you can use it

Steps

1. install following nuget packages in project

Google.Apis.Urlshortener.v1
Google.Apis.Urlshortener.v1. Data
Google.Apis.Services

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}");
 Console.ReadKey();
 }
 }
}

 

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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