Upload video to YouTube - Exceeded Quota error

Viewed 553

I'm trying to develop an app that uploads a video to YouTube.

Whenever I try to call the upload routine, i'm getting an error stating I have exceeded my Quota. But in the Quota usage screens it says that the data is unavailable.

I've even created a new project and used the new credentials to ensure it wasn't something funny with the old project (in the google developer acc), but still getting the same.

    public class ClipUploader
{
    public static async Task UploadClip(string title, string path)
    {
        string vId = "";
        UserCredential credential;
        using (var stream = new FileStream(@"C:\Users\andre\source\repos\YouTubeClippingBot\TheBot\uploadClientSecret.json", FileMode.Open, FileAccess.Read))
        {
            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.FromStream(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
            );
        }


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

        var video = new Video();
        video.Snippet = new VideoSnippet();
        video.Snippet.Title = title;
        video.Snippet.Description = "Default Video Description";
        video.Snippet.Tags = new string[] { "tag1", "tag2" };
        video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
        video.Status = new VideoStatus();
        video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"
        var filePath = path; // Replace with path to actual movie file.

        using (var fileStream = new FileStream(filePath, FileMode.Open))
        {
            var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
            videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
            videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;

            await videosInsertRequest.UploadAsync();

        }
    }

    static void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress progress)
    {
        switch (progress.Status)
        {
            case UploadStatus.Uploading:
                Console.WriteLine("{0} bytes sent.", progress.BytesSent);
                break;

            case UploadStatus.Failed:
                Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception);
                break;
        }
    }

    static void videosInsertRequest_ResponseReceived(Video video)
    {
        Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id);
        //Then I need to somehow send this back to chat....
    }
}

So i'm not sure why I am getting a quota error. The code is from the YouTube github pages, wanted to get it bascially working then I can tailor it to what I actually need to do.

Any suggestions will be happily received.

1 Answers

Your getting the error because you have exceeded your current quota.

You need to understand how the quota system works for this api Intro to YouTube API and cost based quota for beginners 2021.. You have a limit of quota points that you can spend on requests. Each request type has a different quota cost when you run that request the points will be deducted from your total quota. This limit is defined in the Google cloud console. Its cost based and not the number of requests you make.

Video.insert for example costs 1600. So if you have a 10000 limit like i do then you can max upload 6 videos a day.

what is your current quota.

Go to Google cloud console on the left go to library then search for the YouTube data api.

Click the manage button then go to quota. Check what your current quota is

enter image description here

request quota increase.

at the top of this page you can also request additional quota

enter image description here

Usage reports

Don't count on the usage reports they are not very accurate go by the error message you are getting.

Related