public void RefreshGoogleAuthToken()
{
string authUrl = "https://www.google.com/accounts/ClientLogin";
var data = new NameValueCollection();
data.Add("Email", this.SenderID);
data.Add("Passwd", this.Password);
data.Add("accountType", "GOOGLE_OR_HOSTED");
data.Add("service", "ac2dm");
data.Add("source", this.ApplicationID);
var wc = new WebClient();
try
{
var authStr = Encoding.ASCII.GetString(wc.UploadValues(authUrl, data));
//Only care about the Auth= part at the end
if (authStr.Contains("Auth="))
googleAuthToken = authStr.Substring(authStr.IndexOf("Auth=") + 5);
else
throw new GoogleLoginAuthorizationException("Missing Auth Token");
}
catch (WebException ex)
{
var result = "Unknown Error";
try { result = (new System.IO.StreamReader(ex.Response.GetResponseStream())).ReadToEnd(); }
catch { }
throw new GoogleLoginAuthorizationException(result);
}
}