C# GoogleWebAuthorizationBroker.AuthorizationAsync冻结

C# GoogleWebAuthorizationBroker.AuthorizationAsync冻结,c#,oauth-2.0,google-api,youtube-api,google-api-dotnet-client,C#,Oauth 2.0,Google Api,Youtube Api,Google Api Dotnet Client,我有一个C#.net网络应用程序,我用它将视频上传到Youtube。这在大约6个月前起作用,但现在已经停止。当我在本地计算机上通过Visual Studio启动网站时,以下代码挂起: UserCredential credential; using (var auth_stream = new FileStream(Server.MapPath("~/YouTube/client_secrets.json"), FileMode.Open, FileAccess.Read))

我有一个C#.net网络应用程序,我用它将视频上传到Youtube。这在大约6个月前起作用,但现在已经停止。当我在本地计算机上通过Visual Studio启动网站时,以下代码挂起:

     UserCredential credential;
    using (var auth_stream = new FileStream(Server.MapPath("~/YouTube/client_secrets.json"), FileMode.Open, FileAccess.Read))
    {
        credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.Load(auth_stream).Secrets,
            // This OAuth 2.0 access scope allows an application to upload files to the
            // authenticated user's YouTube channel, but doesn't allow other types of access.
            new[] { YouTubeService.Scope.YoutubeUpload },
            "user",
            CancellationToken.None
        );
    }
在查看了有关堆栈溢出的其他帖子后,我还尝试了以下内容:

     UserCredential credentialS;
     using (var auth_stream = new FileStream(Server.MapPath("~/YouTube/client_secrets.json"), FileMode.Open, FileAccess.Read))
     {
         credentialS = await GoogleWebAuthorizationBroker.AuthorizeAsync(
             new ClientSecrets
             {
                 ClientId = "blahblah-myDetailsBlahBLah.apps.googleusercontent.com",
                 ClientSecret = "myClientSecret",
             },
             // This OAuth 2.0 access scope allows an application to upload files to the
             // authenticated user's YouTube channel, but doesn't allow other types of access.
             new[] { YouTubeService.Scope.YoutubeUpload },
             "user",
             CancellationToken.None
         );
     }
我还注意到我使用的是谷歌API的1.7.0-beta版,所以我通过PackageManager控制台升级到1.8.2版

我还通过谷歌开发者控制台生成了一个新的客户端密码,并将其用于我的网站

但是在尝试这些步骤之后,对GoogleWebAuthorizationBroker.AuthorizationAsync的调用仍然挂起。 我注意到,我的本地浏览器中的网站会刷新,好像它正在尝试连接,但呼叫从未成功


我该如何解决这个问题呢?

我也使用谷歌日历API遇到了这个问题

我的应用程序是从各种在线资源中抓取通知,并将其发布到共享的谷歌日历上

它在开发环境中可以正常工作,但在我将其部署到一个虚拟机时却不行,在该虚拟机中,它每15分钟使用该虚拟机中的服务帐户作为windows计划任务运行一次

我记得第一次设置它时,我必须在浏览器中完成授权步骤,但当作为计划任务运行时,它没有被触发

我找不到方法让它通过浏览器提示再次授予访问权限

由于服务帐户C:\Users\\Documents.credentials\calendar dotnet quickstart文件夹创建得很好,我只是从我的开发环境中的同一文件夹复制了Google.api.Auth.OAuth2.Responses.TokenResponse-user,现在可以正常工作了

这可能不是最好的或最终的解决办法,但它是有效的

我怀疑,如果我作为计划任务的服务用户登录并从命令提示符下运行,那么浏览器会提示我授予授权


希望这对其他人有所帮助。

打开检查%appData%文件夹,查找名为的文件夹,其中包含类似YouTube的内容。请删除该文件夹,然后重试。或者只是将“user”改为“user2”,然后再试一次。因为Roaming\Google.api.Auth是一个空文件夹,所以我删除了它,并将user改为user2,但我仍然有同样的问题。您是否有防火墙阻止身份验证服务器?我也有同样的问题。曾经有效的代码不再有效。我的解决方法是在Google auhorization网页中进行授权,然后杀死我的应用程序并重新启动它。重新启动后,它将读取第一步中存放的令牌文件并继续执行,没有问题。很抱歉,我没有进一步的想法。