Google Calendar V3 hangs when used outside local environment (asp.net)

809 views
Skip to first unread message

Hewbhurt Gabon

unread,
Nov 21, 2014, 9:02:24 AM11/21/14
to google-ca...@googlegroups.com
Hello again Google Calendar API Team!

I am somewhat in panic mode right now. I only got month left and Google will be shutting down v2 again. I am stock to a similar situation to this post at stockoverflow. http://stackoverflow.com/questions/25914644/google-calendar-v3-hangs-when-used-outside-local-environment-asp-net

 I'm working on a wrapper for the .net version of the Google Calendar API. The authentication is rather simple and working fine locally (localhost:port).

            var gFolder = System.Web.HttpContext.Current.Server.MapPath("/App_Data/MyGoogleStorage");
           
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
               
new ClientSecrets
               
{
                   
ClientId = "xxxxxxxxx.apps.googleusercontent.com",
                   
ClientSecret = "xxxxxxxxxxxx0Kq9gwLdQwB1",
               
},
               
new[] { CalendarService.Scope.Calendar },
               
"user",
               
CancellationToken.None,
               
new FileDataStore(gFolder)).Result;
           
// Create the service.
           
var service = new CalendarService(new BaseClientService.Initializer()
           
{
               
HttpClientInitializer = credential
           
});  


The issue is, though, when the same code is deployed to production (secrets changed, of course), the application just hangs whenever I try to access the data. There's no exception, no error code, it just keeps loading forever.

Any advice?

Lucia Fedorova

unread,
Nov 24, 2014, 8:07:10 PM11/24/14
to google-ca...@googlegroups.com
Hi Hewbhurt,
is the storage path accessible after deployment?

Hewbhurt Gabon

unread,
Nov 25, 2014, 10:51:45 PM11/25/14
to google-ca...@googlegroups.com
Hello ms. Lucia! First of all, I would like to thank you for replying to my post. I am happy that somehow, someone from Google Calendar API Team is showing concern to desperate v1/v2 developer like us. Ms Lucia, I have already solve or humbly got a solution for the above issue. I have shared it at stockoverflow. http://stackoverflow.com/a/27073729/4280827

The code below works for me. It is my own revision of Google API Simple Task ASP.NET sample.

Add these usings...
using System.IO;
using System.Threading;

using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Auth.OAuth2.Web;
using Google.Apis.Services;
using Google.Apis.Util.Store;

And these...
CalendarService service;
static string gFolder = System.Web.HttpContext.Current.Server.MapPath("/App_Data/MyGoogleStorage");


protected void Page_Load(object sender, EventArgs e)
{
   
IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(
       
new GoogleAuthorizationCodeFlow.Initializer
       
{
           
ClientSecrets = GetClientConfiguration().Secrets,
           
DataStore = new FileDataStore(gFolder),
           
Scopes = new[] { CalendarService.Scope.Calendar }
       
});

   
var uri = Request.Url.ToString();
   
var code = Request["code"];
   
if (code != null)
   
{
       
var token = flow.ExchangeCodeForTokenAsync(UserId, code,
            uri
.Substring(0, uri.IndexOf("?")), CancellationToken.None).Result;

       
// Extract the right state.
       
var oauthState = AuthWebUtility.ExtracRedirectFromState(
            flow
.DataStore, UserId, Request["state"]).Result;
       
Response.Redirect(oauthState);
   
}
   
else
   
{
       
var result = new AuthorizationCodeWebApp(flow, uri, uri).AuthorizeAsync(UserId,
           
CancellationToken.None).Result;
       
if (result.RedirectUri != null)
       
{
           
// Redirect the user to the authorization server.
           
Response.Redirect(result.RedirectUri);
       
}
       
else
       
{
           
// The data store contains the user credential, so the user has been already authenticated.
            service
= new CalendarService(new BaseClientService.Initializer
           
{
               
ApplicationName = "Calendar API Sample",
               
HttpClientInitializer = result.Credential
           
});
       
}
   
}
}


public static GoogleClientSecrets GetClientConfiguration()
{
   
using (var stream = new FileStream(gFolder + @"\client_secrets.json", FileMode.Open, FileAccess.Read))
   
{
       
return GoogleClientSecrets.Load(stream);
   
}
}

I know, a lot of us here is badly needing for this working sample. I hope this helps.
Reply all
Reply to author
Forward
0 new messages