我正在尝试更新 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 sameID
.)
除此之外,遇到错误
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/