protected void Page_Load(object sender, EventArgs e) { this.RegisterAsyncTask( new PageAsyncTask( async ct => { var google = new GoogleConsumer(); if (google.ConsumerKey != null) { this.MultiView1.ActiveViewIndex = 1; if (!IsPostBack) { // Is Google calling back with authorization? var accessTokenResponse = await google.ProcessUserAuthorizationAsync(this.Request.Url); if (accessTokenResponse != null) { this.AccessToken = accessTokenResponse.AccessToken; } else if (this.AccessToken.Token == null) { // If we don't yet have access, immediately request it. Uri redirectUri = await google.RequestUserAuthorizationAsync(GoogleConsumer.Applications.Contacts); this.Response.Redirect(redirectUri.AbsoluteUri); } } } })); }