将 'madeForKids' 参数添加到 'youtube.liveBroadcasts.insert' API 时出现 500 错误

问题描述:

我有一个关于如何在youtube.liveBroadcasts.insert"API 中使用madeForKids"的问题.

I have one question about how to use 'madeForKids' in 'youtube.liveBroadcasts.insert' API.

当我不使用这个参数时,youtube的用户界面会弹出一个窗口让我选择它是否适合儿童.我不希望它显示这个窗口.我想用 API 设置这个值.但是当我添加这个参数时,它总是会响应一个500错误.

When I don't use this parameter, the user interface of youtube will pop up a window to let me choose wether it is made for kids. I don't want it to show this window. I want to set this value with API. But when I added this parameter, it will always response a 500 error.

我的代码基于JS如下:

My codes is based on JS as follows:

    this.youtube.liveBroadcasts.insert(
      {
        auth: this.oauth2Client,
        part: "snippet,contentDetails,status",
        resource: {
          snippet: {
            title: title,
            scheduledStartTime: scheduledStartTime
          },
          status: {
            madeForKids: "false",
            selfDeclaredMadeForKids: "false",
            lifeCycleStatus: "live",
            privacyStatus: "public"
          },
          contentDetails: {
            rojection: "360",
            monitorStream: {
              enableMonitorStream: false
            }
          }
        }
      },
      function (err, response) {
        if (err) {
          console.log("The API:createLiveBroadCast returned an error: " + err);
          reject(new Error(err));
        } else {
          console.log(response);
          resolve(response);
        }
      }
    );

此外,我使用的是最新的 googleapis:^48.0.0".

Additionally, I am using the latest googleapis: "^48.0.0".

谁能帮帮我?非常感谢!

Can anyone help me ? Thanks a lot !

您无法在 LiveBroadcast 中设置状态属性.插入 LiveBroadcast 后,您必须更新视频资产并在那里设置状态属性.使用您刚刚添加的 LiveBroadcast.ID.您必须同时重置标题和描述,否则它们将被设置为空.

You cannot set the status attribute in LiveBroadcast. After you insert LiveBroadcast, you must update the video asset and set the status attributes there. Use the LiveBroadcast.ID you just added. You must reset the title and description at the same time or they will get set to null.

像这样:

       var videoRequest = youtubeService.Videos.Update(
            new Video {
                Id = "xxxxxx",
                Kind = "youtube#video",
                Snippet = new VideoSnippet
                {
                    Title = "updated title",
                    CategoryId = "28"
                },
                Status = new VideoStatus
                {
                    PrivacyStatus = "unlisted",
                    SelfDeclaredMadeForKids = false
                }
            },
            "snippet,status"
        );
        var videoResponse = videoRequest.Execute();