scala - 更新 youtube 直播隐私状态

标签 scala youtube youtube-api youtube-data-api youtube-livestreaming-api

我正在尝试更新 scala 中 LiveBroadcast 的隐私状态(使用 java jdk)。这是我的工作流程:

使用 private 创建直播隐私状态

val snippet = new LiveBroadcastSnippet()
    .setTitle(title)
    .setScheduledStartTime(YouTubeDateTime.now())
    .setChannelId(channel.getId)

val status = new LiveBroadcastStatus()
  .setPrivacyStatus("private")

val broadcast = new LiveBroadcast()
  .setKind("youtube#liveBroadcast")
  .setSnippet(snippet)
  .setStatus(status)

val request = youtube.liveBroadcasts()
  .insert("snippet,status,contentDetails", broadcast)

request.execute

将直播转至 testing (如果绑定(bind)的 LiveStream 处于事件状态)
val request = youtube.liveBroadcasts
    .transition(lifeCycleStatus.toString, broadcast.getId, "status")

request.execute

对流感到满意后,将 LiveBroadcast 隐私设置为 public
val status = new LiveBroadcastStatus().setPrivacyStatus("public")

broadcast.setStatus(status)

val request = youtube.liveBroadcasts.update("status", broadcast)

request.execute()

最后一部分不起作用,而是返回 400 响应:
400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "youtube.part",
    "location" : "part",
    "locationType" : "parameter",
    "message" : "{0}",
    "reason" : "unexpectedPart"
  } ],
  "message" : "{0}"
}

做同样的请求 here有效,所以我不确定我做错了什么。

任何人都可以帮忙吗?

最佳答案

我可能错了,但我认为您还应该添加 id直播请求中的参数。这是ID YouTube 分配以唯一标识广播的内容。

您可能需要遵循 Life of a Broadcast 中讨论的有关如何创建和管理直播的指南。其中还提到在设置广播时处理 API 响应:

Your code should extract and store the id from that resource as you will need that value to identify the broadcast in future API requests. (You can also identify the video resource that corresponds to the liveBroadcast resource using the same ID.)



除此之外,遇到错误400 Bad Request带有指定的详细信息 unexpectedPart ,如 YouTube Data API - Errors 中的常见请求错误所述, 意思是:

The request's part parameter specifies an unexpected value.

关于scala - 更新 youtube 直播隐私状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39546936/

相关文章:

Scala Map#get 和 Some() 的返回

java - YouTube API too_long 对短关键字的错误代码?

javascript - 在视频元素顶部移动时,JQuery UI 可调整大小/可拖动丢失 'grip'

scala - Guice Multibinder 不适用于 Play 框架

eclipse - 是否可以使用 Eclipse IDE 和 GAE 插件通过 PlayFramework 开发和部署 Scala 应用程序?

scala - 在逆变位置使用协变类型是否有其他选择?

c# - 为什么尝试将视频文件上传到 youtube 时出现 InvalidCredentialsException?

youtube - 获取youtube下载链接[4k,1080px]使用API​​ v3

video - 用ffmpeg剪辑视频,没有输出

youtube-api - 如何获取我 channel 中的所有 youtube 视频 URLS?