I already wasted my full day for finding sample code for Google's Service Account OAuth2 in C#.NET for URL Shortener API.
I am trying to use shortener api with server to server request.
Please help me.
Thanks
Using Json.Net library (you can get the API key from here)
string longURL="http://www.google.com";
string url = "https://www.googleapis.com/urlshortener/v1/url?key=" + apiKey;
WebClient client = new WebClient();
client.Headers["Content-Type"] = "application/json";
var response = client.UploadString(url,JsonConvert.SerializeObject(new { longUrl = longURL }));
var shortUrl = (string)JObject.Parse(response)["id"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With