IIS .Net运行时错误上的Googlewebauthorizationbroker.AuthorizeAsync

时间:2019-01-17 06:39:55

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

我使用const arr = [ { name: "aa", type: "total", count: 28394 }, { name: "aa", type: "featured", count: 4 }, { name: "aa", type: "noAnswers", count: 5816 }, { name: "ba", type: "total", count: 148902 }, { name: "ba", type: "featured", count: 13 }, { name: "ba", type: "noAnswers", count: 32527 }, { name: "cc", type: "total", count: 120531 }, { name: "cc", type: "featured", count: 6 }, { name: "cc", type: "noAnswers", count: 24170 } ]; var hash = {}; var result = []; for(var i=0; i < arr.length; i++){ if(!arr[i].name in hash) hash[arr[i].name] = {} let temp = {}; temp[arr[i].type] = arr[i].count; hash[arr[i].name] = Object.assign(temp, hash[arr[i].name]); } for(var key in hash) result.push({name : key, ...hash[key]}) console.log(result) 来获取令牌。我在网站上使用“过程”,并致电ConsloeApp来获取Google Calender的数据。它在Visual Studio(2017)上可以完美运行,但是当我放入IIS时,它没有打开浏览器进行授权,并且IIS出现.Net RunTime错误。

这是我的代码。希望可以解决这个问题。

Googlewebauthorizationbroker.AuthorizeAsync()

这是错误消息。 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

1 个答案:

答案 0 :(得分:1)

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

您需要使用专为与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")
            });