首页 文章

GoogleWebAuthorizationBroker在C#中引发异常

提问于
浏览
-1

我正试图在Windows 8应用程序中使用 OAuth 与Google进行身份验证 . 我正在使用Google .NET客户端API,关注此tutorial . 但是当我使用 GoogleWebAuthorizationBroker 类时,我不断收到异常 .

我所拥有的代码是从链接教程中复制/粘贴的 . client_secrets.json包含我从Google API控制台下载的文件 . 我确实检查它是否已复制到已安装的应用程序,我可以打开它 . Calendar API已开启 .

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

在try / catch中包围这一行告诉我它失败的原因是:

System.AggregateException:发生一个或多个错误 . ---> System.Exception:进程意外终止 . (来自HRESULT的异常:0x8007042B)位于System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务),位于Google的System.Runtime.CompilerServices.TaskAwaiter1.GetResult() . apis.Auth.OAuth2.AuthorizationCodeBroker . <ReceiveCodeAsync> d__10.MoveNext()在c:\ code \ google.com \ google-api-dotnet-client \ default \ Tools \ Google.Apis.Release \ bin \ Debug \ output \ default \ Src \ GoogleApis.Auth.WinRT \ OAuth2 \ AuthorizationCodeBroker.cs:第69行---内部异常堆栈跟踪结束---在Microsoft.Runtime.CompilerServices上的Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)位于Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()的Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(任务任务)的.TaskAwaiter.HandleNonSuccess(任务任务),位于Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__0.MoveNext ()在c:\ code \ google.com \ go中ogle-api-dotnet-client \ default \ Tools \ Google.Apis.Release \ bin \ Debug \ output \ default \ Src \ GoogleApis.Auth \ OAuth2 \ AuthorizationCodeInstalledApp.cs:第74行---来自先前位置的堆栈跟踪结束抛出异常的地方---在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处,System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()at c:\ code \ google.com \ google-api-dotnet-client \ default \ Tools \ Google.Apis.Release \ bin \ Debug output \ default \ Src \ GoogleApis.Auth.WinRT \ OAuth2 \ AuthorizationCodeWinRTInstalledApp.cs:第65行---从抛出异常的上一个位置开始的堆栈跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) )在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebug位于c:\ code \ google.com \ google-api-dotnet的Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__6.MoveNext()中的System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()的gerNotification(任务任务) -client \ default \ Tools \ Google.Apis.Release \ bin \ Debug \ output \ default \ Src \ GoogleApis.Auth.WinRT \ OAuth2 \ GoogleWebAuthorizationBroker.cs:第73行---来自先前位置的堆栈跟踪结束,其中异常是抛出---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处于System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务),位于Google.Apis的System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() .Auth.OAuth2.GoogleWebAuthorizationBroker . <AuthorizeAsync> d__0.MoveNext()在c:\ code \ google.com \ google-api-dotnet-client \ default \ Tools \ Google.Apis.Release \ bin \ Debug \ output \ default \ Src \ GoogleApis.Auth.WinRT \ OAuth2 \ GoogleWebAuthorizationBroker.cs:第48行--- stac结束来自抛出异常的先前位置的k跟踪---位于System.Runtime.CompilerServices.TaskAwaiter1.GetResult的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) ()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:第68行 - - >(内部异常#0)System.Exception:进程意外终止 . (来自HRESULT的异常:0x8007042B)在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)at atSystem.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)位于C:\ code \ google中的Google.Apis.Auth.OAuth2.AuthorizationCodeBroker.d__10.MoveNext()中的System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() .com \ google-api-dotnet-client \ default \ Tools \ Google.Apis.Release \ bin \ Debug \ output \ default \ Src \ GoogleApis.Auth.WinRT \ OAuth2 \ AuthorizationCodeBroker.cs:第69行<---

我错过了什么?

2 回答

  • 1

    pelayal在对问题的评论中发表的link提供了解决方案 . 我的 Profiles 有问题 . 创建一个新帐户修复它 .

  • 1

    检查上面

    • Install-Package Microsoft.Bcl.Async

    • 并在您的应用程序中部署他们的dll

相关问题