Google Analytics - Authorising on live site

0

I'm trying to get my C# GA code working on our live site.

It's working fine on my local server.

My GetCredential code:

static async Task<UserCredential> GetCredential()
{
    String filename = HttpContext.Current.Server.MapPath(String.Format("\\App_Data\\{0} Google Analytics.json", projectPrefix) );
    String tempStore = HttpContext.Current.Server.MapPath( String.Format("\\{0}\\tasks\\", projectPath) );

    using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
    {
        const string loginEmailAddress = "my.address@example.com";
        return await GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.Load(stream).Secrets,
            new[] { AnalyticsReportingService.Scope.Analytics },
            loginEmailAddress, CancellationToken.None, 
            new FileDataStore(tempStore, true)
        );
    }
}

When I run it on live I get the following stack trace:

[Win32Exception (0x80004005): Access is denied]
System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) +756 System.Diagnostics.Process.Start() +131
System.Diagnostics.Process.Start(ProcessStartInfo startInfo) +49
Google.Apis.Auth.OAuth2.d__14.MoveNext() +179

[NotSupportedException: Failed to launch browser with "https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&response_type=code&client_id=637677881438-kl0u84oe0hdvi43qfh6k31dgnev1n8l4.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A51727%2Fauthorize%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fanalytics" for authorization. See inner exception for details.]
Google.Apis.Auth.OAuth2.d__14.MoveNext() +348
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 Google.Apis.Auth.OAuth2.d__8.MoveNext() +479 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 Google.Apis.Auth.OAuth2.d__4.MoveNext() +414 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 Google.Apis.Auth.OAuth2.d__1.MoveNext() +286 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 d__3.MoveNext()

I have absolutely no idea why the redirect uri is:

redirect_uri=http%3A%2F%2Flocalhost%3A51727%2Fauthorize%2F

I have never entered in localhost into the list of Authorized JavaScript origins or Authorized redirect URIs. Perhaps because I have previously authorised it locally? But the port number is not even close.

I have tried different permutations of OAuth 2.0 client IDs in the https://console.cloud.google.com/apis/credentials page (Both "Web Application" and "Other").

Any ideas?

c#
google-analytics
oauth-2.0
asked on Stack Overflow Apr 2, 2019 by Lee Taylor

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0