Googlewebauthorizationbroker.AuthorizeAsync on IIS .Net RunT



我用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

这是错误消息。在此处输入图像描述

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

GoogleWebAuthorizationBroker在IIS上运行时不会打开浏览器

Google Auth 在 Visual Studio 中运行,但在部署到 IIS 时挂起

GoogleWebAuthorizationBroker.AuthorizeAsync 方法用于已安装的应用程序。它将在运行代码的计算机上打开浏览器窗口。 在 Visual Studio 中运行它的实例中,它工作正常,但一旦您尝试托管它,它将尝试在 Web 服务器上打开浏览器窗口,这将不起作用。

您需要使用GoogleAuthorizationCodeFlow,它专为与Web应用程序一起使用而设计。 你可以在这里找到一个例子,不幸的是它的C#我不知道谷歌.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")
            });

最新更新