【问题标题】:Googlewebauthorizationbroker.AuthorizeAsync on IIS .Net RunTime ErrorIIS .Net 运行时错误上的 Googlewebauthorizationbroker.AuthorizeAsync
【发布时间】:2019-01-17 06:39:54
【问题描述】:

我使用Googlewebauthorizationbroker.AuthorizeAsync() 来获取令牌。我在网站上使用“进程”并调用 ConsloeApp 来获取 Google Calender 的数据。它在 Visual Studio(2017) 上运行良好,但是当我放入 IIS 时,它没有打开浏览器进行授权并且 IIS 得到 .Net RunTime ERROR。

这是我的代码。希望能找到解决这个问题的办法。

Public Sub  Main(args As String())

    Dim userID As String = "xxx"
    Dim Credential As UserCredential

    Dim Stream As New FileStream("~\credentials.json", FileMode.Open, FileAccess.ReadWrite)

    Dim credPath As String = "~\token.json"
    Credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(Stream).Secrets,
        Scopes,
        userID,
        CancellationToken.None,
        New FileDataStore(credPath, True)).Result

    Dim oService As CalendarService = New CalendarService(New BaseClientService.Initializer() With
    {
            .HttpClientInitializer = Credential,
            .ApplicationName = ApplicationName
    })

    Fun_List(oService)

    Console.ReadLine()
End Sub

这是错误信息。 enter image description here

我的问题可能喜欢这个问题。

GoogleWebAuthorizationBroker won't open browser when running on IIS

Google Auth runs in Visual studio but hangs when deployed to IIS

【问题讨论】:

  • 对不起,我的错误。那么我需要提供什么?我不明白。
  • 你说你遇到了运行时错误。请提供完整的异常和堆栈跟踪。
  • @John 我提供了错误信息的图片,谢谢
  • 我会收回我的反对票,但理想情况下应该在您的问题中以文本形式提供该信息。我发现与您的问题最接近的(尽管是 C#)问题是this one
  • 我的问题可能像这样problem。但这没有解决方案。

标签: vb.net google-api google-calendar-api google-api-dotnet-client


【解决方案1】:

GoogleWebAuthorizationBroker.AuthorizeAsync 方法用于已安装的应用程序。它将在运行代码的机器上打开浏览器窗口。在您在 Visual Studio 中运行它的情况下,它可以正常工作,但一旦您尝试托管它,它就会尝试在 Web 服务器上打开浏览器窗口,但无法正常工作。

您需要使用专为与网络应用程序一起使用而设计的 GoogleAuthorizationCodeFlow。你可以找到一个例子 here 不幸的是它的 C# 我不知道任何用于 google .net 客户端库的 VB 示例。

private static readonly IAuthorizationCodeFlow flow =
        new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
            {
                ClientSecrets = new ClientSecrets
                {
                    ClientId = "PUT_CLIENT_ID_HERE",
                    ClientSecret = "PUT_CLIENT_SECRET_HERE"
                },
                Scopes = new[] { DriveService.Scope.Drive },
                DataStore = new FileDataStore("Drive.Api.Auth.Store")
            });

【讨论】:

  • C#没问题,我可以翻译。我知道 MVC 的这种方式。我的项目现在已经使用这种方式了。所以,Googlewebauthorizationbroker.AuthorizeAsync() 看起来并不是 Web 服务器上的最佳方式。感谢您的解决方案。
  • 我找到了带有GoogleAuthorizationCodeFlow 的VB 示例代码。 thisthis。如果有人需要的话。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-31
  • 1970-01-01
  • 2010-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多