GoogleWebAuthorizationBroker在C#中抛出异常



我正试图在Windows 8应用程序中使用OAuth与谷歌进行身份验证。在本教程之后,我将使用Google.NETClientneneneba API进行此操作。然而,当我使用GoogleWebAuthorizationBroker类时,我总是遇到一个异常。

我的代码是从链接的教程中复制/粘贴的。client_secrets.json包含我从Google API控制台下载的文件。我确实检查了它是否被复制到已安装的应用程序中,并且我可以打开它。日历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(任务task),位于System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Google.Apis.Auth.OAuth2.AuthorizationCodeBroker.<ReceiveCodeAsync>d__10.MoveNext() in c:codegoogle.comgoogle-api-dotnet-clientdefaultToolsGoogle.Apis.ReleasebinDebugoutputdefaultSrcGoogleApis.Auth.WinRTOAuth2AuthorizationCodeBroker.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()在Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d_0.MoveNext()在里面c: \code\google.com\google api dotnet client\default\Tools\google.Apis.Release \bin\Debug\output\default\Src\GoogleApis.Auth\OAuth2\AuthorizationCodeInstalledApp.cs:line74---从上一个引发异常的位置开始的堆栈结尾跟踪--在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Google.Apis.Auth.OAuth2.AuthorizationCodeWinRTInstalledApp.<AuthorizeAsync>d__0.MoveNext() in c:codegoogle.comgoogle-api-dotnet-clientdefaultToolsGoogle.Apis.ReleasebinDebugoutputdefaultSrcGoogleApis.Auth.WinRTOAuth2AuthorizationCodeWinRTInstalledApp.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()在Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d_6.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:line73---从上一个引发异常的位置开始的堆栈结尾跟踪--在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__0.MoveNext() in c:codegoogle.comgoogle-api-dotnet-clientdefaultToolsGoogle.Apis.ReleasebinDebugoutputdefaultSrcGoogleApis.Auth.WinRTOAuth2GoogleWebAuthorizationBroker.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()位于中的kk_youtube_metro.GroupedItemsPage.d_5.MoveNext()c: \Users\Karol\Documents\Visual Studio2012\Projects\kk youtube metro\kk youttube metro\GroupedItemsPage.xaml.cs:line68--->(内部异常#0)系统异常:进程意外终止。(HRESULT:0x8007042B中的异常)System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务task),位于System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()在Google.Apis.Auth.OAuth2.AuthorizationCodeBroker.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:line69<---

我缺少什么?

pelayal在问题评论中发布的链接提供了解决方案。我的个人资料有问题。创建一个新帐户修复了它。

检查上方

  • 安装程序包Microsoft.Bcl.Async
  • 并将它们的dll与您的应用程序一起部署

相关内容

  • 没有找到相关文章

最新更新