Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
359 views
in Technique[技术] by (71.8m points)

javascript - The request cannot be completed because you have exceeded your quota

I tried to use the javascript MediaUploader.js to upload youtube video to my own account, for some reason, I got this error in onError function:

"errors": [
   {
    "domain": "youtube.quota",
    "reason": "quotaExceeded",
    "message": "The request cannot be completed because you have exceeded your u003ca href="/youtube/v3/getting-started#quota"u003equotau003c/au003e."
   }
  ],
  "code": 403,
  "message": "The request cannot be completed because you have exceeded your u003ca href="/youtube/v3/getting-started#quota"u003equotau003c/au003e."

I only tested a few times today, but got this strange error.

var signinCallback = function (tokens, file){
console.log("signinCallback tokens: ",tokens);
if(tokens.accessToken) { //tokens.access_token
  console.log("signinCallback tokens.accessToken: ",tokens.accessToken);
  var metadata = {
    id: "101",
    snippet: {
      "title": "Test video upload",
      "description":"Description of uploaded video",
      "categoryId": "22",//22
      "tags": ["test tag1", "test tag2"],
    },
    status: {
        "privacyStatus": "private",
        "embeddable": true,
        "license": "youtube"
    }
    };
  console.log("signinCallback Object.keys(metadata).join(','): ",Object.keys(metadata).join(','));
  var options = {
    url: 'https://www.googleapis.com/upload/youtube/v3/videos?part=snippet%2Cstatus&key=<my api key>',

    file: file,
    token: tokens.accessToken,
    metadata: metadata,
    contentType: 'application/octet-stream',//"video/*",
    params: {
      part: Object.keys(metadata).join(',')
    },
    onError: function(data) {
      var message = data;
      // Assuming the error is raised by the YouTube API, data will be
      // a JSON string with error.message set. That may not be the
      // only time onError will be raised, though.
      try {
        console.log("signinCallback onError data: ",data);
        if(data!="Not Found"){
            var errorResponse = JSON.parse(data);
            message = errorResponse.error.message;
            console.log("signinCallback onError message: ",message);
            console.log("signinCallback onError errorResponse: ",errorResponse);
        }else{

        }
      } finally {
        console.log("signinCallback error.... ");
      }
    }.bind(this),
    onProgress: function(data) {
      var currentTime = Date.now();
      var bytesUploaded = data.loaded;
      var totalBytes = data.total;
      // The times are in millis, so we need to divide by 1000 to get seconds.
      var bytesPerSecond = bytesUploaded / ((currentTime - this.uploadStartTime) / 1000);
      var estimatedSecondsRemaining = (totalBytes - bytesUploaded) / bytesPerSecond;
      var percentageComplete = (bytesUploaded * 100) / totalBytes;
      console.log("signinCallback onProgress bytesUploaded, totalBytes: ",bytesUploaded, totalBytes);
      console.log("signinCallback onProgress percentageComplete: ",percentageComplete);
    }.bind(this),
    onComplete: function(data) {
      console.log("signinCallback onComplete data: ",data);
      var uploadResponse = JSON.parse(data);
      this.videoId = uploadResponse.id;
      //this.pollForVideoStatus();
    }.bind(this)
  }
  MediaUpload.videoUploader(options);
}

};

I checked the developer console of my quota, my quota limit is so big, there is no way I exceeded my quota, ex, I have total of 89 queries today, and my quota limit is 10,000 queries/day.

Expected: upload my video to my youtube account successfully. Actual results: quotaExceeded

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Youtube does not give you 10,000 Queries a day, they give you 10,000 units a day; a query can be multiple units, depending on what you're doing:

A simple read operation that only retrieves the ID of each returned resource has a cost of approximately 1 unit.

A write operation has a cost of approximately 50 units.

A video upload has a cost of approximately 1600 units.

If your 89 queries contain video uploads or write operations, then that would explain your issue

More Information: https://developers.google.com/youtube/v3/getting-started#quota


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...