Javascript Youtube 数据 API v3 : Inserting video in a playlist (Video not found)

标签 javascript youtube youtube-api youtube-data-api youtube-javascript-api

当我提交表单时,我正在尝试将视频添加到我在 youtube 上的私有(private)播放列表中。
我请求所选视频的 id,它也在我的控制台中正确打印。
但是当我尝试将视频添加到播放列表时,我收到 404 错误:找不到视频。但是,如果打开错误,我会收到以下消息...

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 }
}

这是我将视频添加到播放列表的代码。
        $('#form1').on('submit', function(e) {
             e.preventDefault();
             var id = $("#idArticle").val();

             var request = gapi.client.youtube.playlistItems.insert({
                part: 'snippet',
                resource: {
                  snippet: {
                    playlistId: 'PLcQyg31odPUkASkMF09QBGqD8qKOQoe-l',
                    resourceId: {
                        videoId: id,
                        kind: "youtube#video",
                    }
                  }
                }
              });
              request.execute(function(response) {
                  console.log(response);
                $('#videoDetails').html('<p>' + response + '</p>');
              });
             console.log("Added.?");
        });

最佳答案

基于此thread ,如果您没有使用 Oauth2 对应用程序进行身份验证,或者您没有随此请求发送 API key ,则可能会出现此问题。

  1. You need a Google Account to access the Google Developers Console, request an API key, and register your application.
  2. Create a project in the Google Developers Console and obtain authorization credentials so your application can submit API requests.
  3. After creating your project, make sure the YouTube Data API is one of the services that your application is registered to use:
    a. Go to the Developers Console and select the project that you just registered. b. Open the API Library in the Google Developers Console. If prompted, select a project or create a new one. In the list of APIs, make sure the status is ON for the YouTube Data API v3.
  4. If your application will use any API methods that require user authorization, read the authentication guide to learn how to implement OAuth 2.0 authorization.

see Getting started

关于Javascript Youtube 数据 API v3 : Inserting video in a playlist (Video not found),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51935417/

相关文章:

javascript - 数字格式化函数 : What algorithm is used for rounding values ending in 5?

javascript - 调整由 JS 添加的特定 TinyMCE 编辑器的大小

youtube - 视频代码:静音和自动播放

youtube - 将Youtube Feeds API2升级到API3

google-analytics - YouTube 分析报告 API : Empty Video Id for User Activity Report

javascript - 如何使用 Meteor 进行 API 调用并将 header 传递给它

javascript - 配置 - 是否有基于 Web 的 github 连接工具?

html - 没有黑条的响应式全屏 youtube 视频?

C++ 文本动画错误 C2397

javascript - 来自youtube搜索的Ajax自动完成功能,跨域请求被阻止