【问题标题】:Youtube Data Api Authorization at Windows Service get timeoutWindows 服务中的 Youtube 数据 Api 授权超时
【发布时间】:2016-03-11 11:50:35
【问题描述】:

我为定时 Youtube 上传开发了一个小的 C# 应用程序。 我有一个 UI WPF 应用程序,它应该通过 WCF 与后台服务进行通信。 这个后台服务可以做所有与 Youtube 相关的事情。

我意识到后台服务是正常工作的windows服务。

但是,如果 Windows 服务尝试获取凭据,我将遇到 WCF 超时。据我调试问题,调用后:

using(var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
        {
            _credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                new[]{YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload},
                "user",
                CancellationToken.None);
        }

什么都没有发生。通常会出现一个浏览器窗口以授予应用程序访问权限(如果我在普通应用程序中执行相同操作,它会这样做)。

这与 windows-service 的访问级别有关吗?我用过ServiceAccount.LocalSystem

清关: 如果我在普通的控制台应用程序中实现它,整个 WCF 和 youtube 代码可以正常工作,但在 Windows 服务中它会超时。

【问题讨论】:

    标签: c# windows-services youtube-data-api


    【解决方案1】:

    试试这个:

    var _credential = await 
    GoogleWebAuthorizationBroker.AuthorizeAsync(UriFromRelativePath(this, "/API/client_secret.json"), new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload },
                    "user",
                    CancellationToken.None);
    
    
    public static Uri UriFromRelativePath(FrameworkElement parent, string path)
        {
            try
            {
                var uri = new Uri(parent.BaseUri, path);
    
                return uri;
            }
            catch (Exception ex)
            {
    
                throw new Exception(ex.Message);
            }
        }
    

    【讨论】:

    • 但是GoogleWebAuthorizationBroker.AuthorizeAsync 没有使用 Uri 的重载?我正在使用 Youtube-Data-Api v3
    猜你喜欢
    • 1970-01-01
    • 2012-01-03
    • 2017-05-16
    • 2017-11-13
    • 2015-09-14
    • 2018-11-03
    • 1970-01-01
    • 2017-06-07
    • 2017-09-24
    相关资源
    最近更新 更多