7

I have been using the Google API Client Library for .NET for loading Google Analytics data into my application:

Recently though I have found it to have started freezing up completely. The Execute() command makes a connection to the Google server.

It makes a successful request to :

 https://accounts.google.com/o/oauth2/token

which returns something like :

{
  "access_token" : "ya30.HAKlQSGZo2GnK5wxlxx9TLTQUyD9Xkt7AZxuQnDY-KhJuCyrCtN_xHIP",
  "token_type" : "Bearer",
  "expires_in" : 3600
} 

But then never returns from the Execute call.

The same code in a console app returns immediately, but in IIS it is currently never returning.

In a previous version it worked just fine (I'm not exactly sure which version it changed).

I have Load User Profile set to true.

What could be causing this?

   var SERVICE_ACCOUNT_PKCS12_FILE_PATH = @"C:\TEMP\GoogleAnalytics-privatekey.p12";
   X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);


   // Create credentials (not my real login here)
   ServiceAccountCredential credential = new ServiceAccountCredential(
      new ServiceAccountCredential.Initializer("86987278011-ctegcus4og7kn6oigkrv8po5pf67bbgj@developer.gserviceaccount.com")
      {
          Scopes = new[] { AnalyticsService.Scope.AnalyticsReadonly }
      }.FromCertificate(certificate));

   // Create the service
   var service = new AnalyticsService(new BaseClientService.Initializer()
   {
       HttpClientInitializer = credential,
       ApplicationName = "Google Analytics Application",

   });

   // get accounts
   accounts = service.Management.Accounts.List();
   var items = accounts.Execute();
skyfree
  • 867
  • 2
  • 10
  • 29
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
  • Are you calling from within the context of a web request? I have a similar set-up (that is running on IIS), but I'm using Hangfire to run it as a scheduled event. I haven't tried running it within a request. – James Haug Nov 08 '15 at 14:00
  • I have the exactly same problem. At first, Google API client library v1.9.0 was used in my project. Just a few days before, some Drive APIs requests stopped working. So, I upgraded the API client library to the latest version, but things got worse, the request was frozen in the first get-user request, just like you. Have no idea how to fix it. – skyfree Nov 09 '15 at 06:09
  • At this time I wasn't really using experiments so I just cheated and disabled it after a few hours tinkering and getting nowhere. Surprised I couldn't find anything else on this. Sorry :-/ – Simon_Weaver Nov 09 '15 at 06:10
  • @Simon_Weaver, my application is a desktop app. Same problem as yours. – skyfree Nov 09 '15 at 06:11
  • It ran fine for me when I created a console app. Do you know the exact version where it broke for you. Perhaps we could fine a feature log - should have already checked that I suppose! – Simon_Weaver Nov 09 '15 at 09:24
  • @JamesHaug yes it is. I have an ExperimentsManager that just updates itself if it's been more than 5 hours. One of those things I always intended to move out to something like hangfire but never did. Ps I suppose I should go look up what hangfire is now :) – Simon_Weaver Nov 09 '15 at 09:26
  • @Simon_Weaver There are a few things about Hangfire I dislike ( so far ), but it offers a fast scalable solution. Probably my biggest gripe so far is the logging/polling for current job status's. I don't see any built-in way to update the hangfire admin panel to show messages from various jobs. I looked at some other options, and I must say hangfire has been the more pleasant of the group. – James Haug Nov 09 '15 at 20:30
  • @Simon_Weaver The version of my Client Library is 1.9.3. The same HTTP GET request works great in Google API playground. But it stuck in my WinForm desktop app without any response or exception. Old versions of Client lib still work, but seems not as stable as before. Now, I have to roll back to old versions – skyfree Nov 10 '15 at 00:25
  • @Simon_Weaver I assume this problem only exists in Service Account 2Legged OAuth authentication. So, this problem hasn't received a lot of attention yet. The new client lib might not well-compatible with the domain-wide auth. – skyfree Nov 10 '15 at 00:40
  • @skyfree FYI I'm not sure if you were referring to windows domain - but I have a single server not on a domain. It also fails on my Win 8.1 laptop, also not on a domain – Simon_Weaver Nov 10 '15 at 18:29
  • @Simon_Weaver No, it's not windows AD domain. I mean the Google Apps domain. The new lib works well for Google personal account, not for service account. – skyfree Nov 17 '15 at 01:38
  • I'm running it under my personal Gmail for an analytics account for my company which I created myself. Hmm – Simon_Weaver Nov 17 '15 at 03:18

1 Answers1

3

As explained in Google Calendar API - Not Returning From Execute() C#, we currently have a bug in the latest version of Google.Apis.Auth v 1.9.3.

We already have a fix for it, in our repository (https://github.com/google/google-api-dotnet-client), so you can test it yourself with the Analytics API (https://developers.google.com/resources/api-libraries/download/analytics/v3/csharp).

A new release of the library is planned to be in the next few weeks so stay tuned - http://google-api-dotnet-client.blogspot.com/


Update (Dec 15th): New NuGet packages for 1.10.0 are available, read more about it at: http://google-api-dotnet-client.blogspot.com/2015/12/announcing-release-of-1100.html

Community
  • 1
  • 1
peleyal
  • 3,472
  • 1
  • 14
  • 25
  • Peleyal, Thank you for your answer. I found that Google Apps service account is under modification right now. A lot of changes are being made in Goolge Developer Console. This is probably the reason why the new version faild on Service Account requests. When will these modifications be completed? Looking foward to the new Developer Console and your new library. – skyfree Nov 17 '15 at 01:29
  • I think that the bug that was introduced (unfortunately) in 1.9.3 is irrelevant to changes in the Google Developer Console. A new library will be released in the next few weeks. – peleyal Nov 17 '15 at 02:44
  • Did someone verify that it works from head now? I want to be confident that it works for everyone before releasing a new version with the fix. – peleyal Nov 17 '15 at 21:36