youtube api令牌上传视频

时间:2014-04-11 13:58:13

标签: c# youtube-api oauth-2.0 token

我正在通过网站重新获取令牌,然后我保存令牌,并在数据库中刷新令牌。然后我正在编写.net程序,将位于我们服务器上的视频上传到youtube。我的问题是获取我正在制作的程序,使用存储的令牌。我正在使用谷歌的一个示例来上传视频。但程序应该使用已经保存的令牌,而不是os要求新的凭据。

目前的代码就是这个。

UserCredential credential;

        //credential.UserCredential(,"",)

        using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
        {
            credential = await 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
            );

        }
        Console.WriteLine("HER");

        var youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
        });

所以相反,我想使用已经保存的令牌。

任何帮助,或指向正确方向的指针都会很棒。谢谢。

1 个答案:

答案 0 :(得分:2)

您可以使用GoogleAuthorizationCodeFlow代替GoogleWebAuthorizationBroker来使用刷新令牌。请参阅答案here

相关问题