C# 如何使用已生成的令牌上传youtube视频?

C# 如何使用已生成的令牌上传youtube视频?,c#,asp.net-mvc,google-api,youtube-api,google-api-dotnet-client,C#,Asp.net Mvc,Google Api,Youtube Api,Google Api Dotnet Client,我是指youtube上传文件 为上传youtube视频提供的链接需要youtube客户端id和all,但我使用以下方法创建了有效令牌 public ActionResult Login() { string clientId = ConfigurationManager.AppSettings["v.YouTube.ClientId"]; string redirect = HttpUtility.UrlEncode(Config

我是指youtube上传文件

为上传youtube视频提供的链接需要youtube客户端id和all,但我使用以下方法创建了有效令牌

public ActionResult Login()
        {
            string clientId = ConfigurationManager.AppSettings["v.YouTube.ClientId"];
            string redirect = HttpUtility.UrlEncode(ConfigurationManager.AppSettings["x.YouTube.CallbackUrl"]);
            string scope = ConfigurationManager.AppSettings["x.YouTube.Scopes"];

            return Redirect($"https://accounts.google.com/o/oauth2/auth?client_id={clientId}&redirect_uri={redirect}&scope={scope}&response_type=code&access_type=offline");
        }
现在我有了一个有效的令牌,我怎么能不使用

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 for full read/write access to the
        // authenticated user's account.
        new[] { YouTubeService.Scope.Youtube },
        "user",
        CancellationToken.None,
        new FileDataStore(this.GetType().ToString())
    );
  }
上述方法


有什么办法吗?

如果您已经有一个访问令牌,那么您可以使用该方法创建一个
GoogleCredential
实例

请注意,以这种方式创建
GoogleCredential
意味着它无法自动刷新访问令牌;因此,它将在大约一小时后过期


然后,如果我创建了GoogleCredential的对象,那么您可以使用这个
GoogleCredential
实例,使用@DalmTo

显示的代码上传到YouTube,在下面的代码中,在创建YouTube服务客户端时,在哪里使用
HttpClientInitializer
。请参阅中的可恢复上传示例