React Native 无法完成请求,因为您已超出配额

6ljaweal  于 2023-02-05  发布在  React
关注(0)|答案(2)|浏览(166)

我试图使用javascript MediaUploader.js上传YouTube视频到我自己的帐户,由于某种原因,我在onError函数中得到了这个错误:

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

我今天只测试了几次,但得到了这个奇怪的错误。

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

};
我检查了我的配额的开发者控制台,我的配额限制是如此之大,我不可能超过我的配额,例如,我今天总共有89个查询,我的配额限制是10,000个查询/天。
预期:上传我的视频到我的YouTube帐户成功。实际结果:超出配额

7kqas0il

7kqas0il1#

Youtube不是每天给予你一万个查询,而是每天给你一万个单位;一个查询可以是多个单元,这取决于您正在执行的操作:
仅检索每个返回资源的ID的简单读取操作的成本大约为1个单位。
写操作具有大约50个单位的成本。
一个视频上传的成本约为1600个单位。
如果您的89个查询包含视频上传或写操作,那么这就可以解释您的问题
更多信息:https://developers.google.com/youtube/v3/getting-started#quota

7kjnsjlb

7kjnsjlb2#

Google开发人员项目已损坏-创建新项目

我对谷歌感到失望,这是我的情况。
我有同样的问题,没有使用,但“配额超过”的React。我的解决方案是创建一个新的项目。我猜这是因为一些内部随着时间的推移而改变,并没有正确地应用到(至少我的)已经存在的项目...
我停止使用AWS有几个原因,并认为谷歌云将是一个令人耳目一新的体验,但这表明我谷歌对待现有的项目一样糟糕的新产品,它扼杀了。
https://github.com/googleapis/google-api-nodejs-client/issues/2263#issuecomment-741892605

相关问题