GoogleWebAuthorizationBroker Throws Exception in C#

-1

I am trying to authenticate with Google using OAuth inside a Windows 8 App. I am using the Google .NET Client API for this, following this tutorial. However I keep getting an exception when I use the GoogleWebAuthorizationBroker class.

The code I have is copy/pasted from the linked tutorial. The client_secrets.json contains the file I downloaded from the Google API Console. I did check that it is copied to the installed app and that I can open it. The Calendar API is turned on.

UserCredential credidential = null;    
credidential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                        new Uri("ms-appx:///Assets/client_secrets.json"),
                        new[] { Uri.EscapeUriString(CalendarService.Scope.Calendar) },
                        "user", CancellationToken.None);

Surrounding this line in try/catch tells me that it fails because of:

System.AggregateException: One or more errors occurred. ---> System.Exception: The process terminated unexpectedly. (Exception from HRESULT: 0x8007042B) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Google.Apis.Auth.OAuth2.AuthorizationCodeBroker.<ReceiveCodeAsync>d__10.MoveNext() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis.Auth.WinRT\OAuth2\AuthorizationCodeBroker.cs:line 69 --- End of inner exception stack trace --- at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__0.MoveNext() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis.Auth\OAuth2\AuthorizationCodeInstalledApp.cs:line 74 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Google.Apis.Auth.OAuth2.AuthorizationCodeWinRTInstalledApp.<AuthorizeAsync>d__0.MoveNext() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis.Auth.WinRT\OAuth2\AuthorizationCodeWinRTInstalledApp.cs:line 65 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__6.MoveNext() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis.Auth.WinRT\OAuth2\GoogleWebAuthorizationBroker.cs:line 73 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__0.MoveNext() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis.Auth.WinRT\OAuth2\GoogleWebAuthorizationBroker.cs:line 48 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at kk_youtube_metro.GroupedItemsPage.d__5.MoveNext() in c:\Users\Karol\Documents\Visual Studio 2012\Projects\kk-youtube-metro\kk-youtube-metro\GroupedItemsPage.xaml.cs:line 68 ---> (Inner Exception #0) System.Exception: The process terminated unexpectedly. (Exception from HRESULT: 0x8007042B) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Google.Apis.Auth.OAuth2.AuthorizationCodeBroker.d__10.MoveNext() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis.Auth.WinRT\OAuth2\AuthorizationCodeBroker.cs:line 69<---

What am I missing?

c#
windows-8
google-api
oauth-2.0
google-api-dotnet-client
asked on Stack Overflow Dec 22, 2013 by kkrizka • edited Aug 1, 2017 by Balagurunathan Marimuthu

2 Answers

1

The link posted by pelayal in the comments to the question provided the solution. There was a problem with my profile. Creating a new account fixed it.

answered on Stack Overflow Dec 26, 2013 by kkrizka
1

Check above

  • Install-Package Microsoft.Bcl.Async
  • and deploy their dlls with your application
answered on Stack Overflow Mar 18, 2014 by user3321978

User contributions licensed under CC BY-SA 3.0