1
votes

I am refering youtube upload document

https://developers.google.com/youtube/v3/code_samples/dotnet

the link given for upload youtube video expecting youube client id and all, but i have created the valid token using following method.

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");
        }

now i have a valid token, how can i upload video without using the

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())
    );
  }

method mentioned above.?

is there any way?

1
See the Resumable Upload example in github.com/google/google-api-dotnet-client-samplesMike Meinz

1 Answers

1
votes

If you already have an access token, then you can create a GoogleCredential instance using the GoogleCredential.FromAccessToken(...) method.

Note that creating a GoogleCredential in this way means that it cannot automatically refresh the access-token; so it will expire in about one hour.

You can then use this GoogleCredential instance to upload to YouTube using the code shown by @DalmTo