GoogleWebAuthorizationBroker.AuthorizeAsync挂起 [英] GoogleWebAuthorizationBroker.AuthorizeAsync Hangs

查看:217
本文介绍了GoogleWebAuthorizationBroker.AuthorizeAsync挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的网站需要从后面的code(asp.net MVC应用程序),将视频上传到YouTube。我试图让谷歌的凭据,但是当我打电话AuthorizeAsync,应用程序只是挂起。我看了一个解决方案遍布无人似乎助阵。我已经搜索谷歌和堆栈溢出明显。大部分我发现了什么提到,应用程序可能无法访问的AppData文件夹,所以我试图改变文件夹位于C盘,D盘,并在实际的Inetpub位置。我测试,发现我能够让应用程序写入到这些位置。

更具体的,用户是我们的管理,客户将视频上传到我们,管理员批准他们。当管理员批准他们,这是张贴在我们的YouTube帐户。管理员不应该做任何事情,但点击确认按钮。

为使这是一个实际的问题,我能做些什么来让过去的AuthorizeAsync?让我知道如果你需要更多的信息。

  UserCredential凭证;
        GoogleWebAuthorizationBroker.Folder =YouTube.Auth.Store;
        使用(VAR流=新的FileStream(CredentialsPath,FileMode.Open,
                             FileAccess.Read))
        {
            凭据= GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(流).Secrets,
                //这个OAuth 2.0用户访问范围允许应用程序文件上传到
                //验证用户的YouTube频道,但不允许其他类型的访问。
                新的[] {} YouTubeService.Scope.YoutubeUpload,
                用户,
                CancellationToken.None,
                新FileDataStore(YouTube.Auth.Store)
            )。结果;
        }


解决方案

找到一种方法,获得通过这一点。

我用GoogleAuthorization codeFLOW代替。这是它原来的样子:

  ClientSecrets秘密=新ClientSecrets()
        {
            客户端Id = CLIENT_ID,
            ClientSecret = CLIENT_SECRET
        };        VAR令牌=新TokenResponse {RefreshToken = REFRESH_TOKEN};
        VAR证书=新UserCredential(新GoogleAuthorization codeFLOW(
            新GoogleAuthorization codeFlow.Initializer
            {
                ClientSecrets =秘密
            }),
            用户,
            令牌);        VAR的服务=新YouTubeService(新BaseClientService.Initializer()
        {
            HttpClientInitializer =凭证,
            应用程序名称=TestProject
        });

Our website needs to upload videos to youtube from the code behind (asp.net mvc application). I'm trying to get the google credentials, but when i call the AuthorizeAsync, the application just hangs. I've looked all over for a solution and none seem to help out. I've already searched for the obvious on google and stack overflow. most of what i found mentioned that the application might not have access the the appdata folder, so i tried changing the folder to be in the c drive, d drive and in the actual inetpub location. i tested and found i was able to have the application write to those locations.

to be more specific, the user is our admin, customers upload videos to us, and the admin approves them. when the admin approves them, it is posted on our youtube account. the admin should not have to do anything but click the approve button.

To make this an actual question, what can i do to get past the AuthorizeAsync? Let me know if you need more info

        UserCredential credential;
        GoogleWebAuthorizationBroker.Folder = "YouTube.Auth.Store";
        using (var stream = new FileStream(CredentialsPath, FileMode.Open,
                             FileAccess.Read))
        {
            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(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,
                new FileDataStore("YouTube.Auth.Store")
            ).Result;
        }

解决方案

Found a way to get passed this.

I used GoogleAuthorizationCodeFlow instead. this is what it turned out to look like:

        ClientSecrets secrets = new ClientSecrets()
        {
            ClientId = CLIENT_ID,
            ClientSecret = CLIENT_SECRET
        };

        var token = new TokenResponse { RefreshToken = REFRESH_TOKEN }; 
        var credentials = new UserCredential(new GoogleAuthorizationCodeFlow(
            new GoogleAuthorizationCodeFlow.Initializer 
            {
                ClientSecrets = secrets
            }), 
            "user", 
            token);

        var service = new YouTubeService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credentials,
            ApplicationName = "TestProject"
        });

这篇关于GoogleWebAuthorizationBroker.AuthorizeAsync挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆