Sunday, August 4, 2013

Unhandled exception in Google Blogger API due to request redirection

Google has everything i can think of!!! I was looking for something by which i can write my own blogger client using which i can create/modify post and i found this wonderful collection of Google API SDK at Not only it has got the Blogger API but i also has the API for other google services like Picasa, Contacts etc. The underlying protocol of these API is based on REST and JSON. Its .NET library source is available at After the check-out when i launched the solution i found it pretty simple to start because the source contains nice samples for each service and to understand the basics classes of the API.

Everything was good until i launched the sample Blogger client and encountered an unhandled exception due to Http redirection. Basically the API raises a Http requests to blogger API URL using an instance of System.Net.HttpWebRequest class and the AllowAutoRedirect property was not set to true due to which the HttpWebRequest.GetResponseStream() method was throwing an unhandled exception whenever the request was redirected. For the resolution, i simply added following line after the call of EnsureWebRequest() in GDataRequest.Execute() method.

(this.webRequest as HttpWebRequest).AllowAutoRedirect = true;

This was my quick resolution to the issue there may me some fix or configuration provided to either avoid or allow redirection. Hope in future this post will help someone like me.

No comments: