2015-10-16 64 views
1

我试图在直播前播放Youtube广播的类别。v3 Youtube API - 如何修改新广播的类别

我刚刚关注了Youtube API documentation,我没有在与广播或直播相关的任何类中找到关于setCategory方法的任何缩减定义。 据此,我发现定义一个类别的唯一方法是创建一个Google_Service_YouTube_VideoSnippet对象。事情是这样的:

$videoSnippet = new Google_Service_YouTube_VideoSnippet(); 
$videoSnippet->setCategoryId("25"); 
//   $snippet->setCategoryId($category); 

$videoInsert = new Google_Service_YouTube_Video(); 
$videoInsert->setSnippet($videoSnippet); 

$insertRequest = $youtube->videos->insert("snippet", $videoInsert); 
$updateRequest = $youtube->videos->update("snippet", $videoInsert); 

在这里,我让与,使一切工作的代码link

我到底错在做什么?这是一个错误吗?

感谢您的建议。

UPDATE

这里我吼叫粘贴,帮助我解决这个问题

$listResponse = $youtube->videos->listVideos("snippet", 
    array('id' => $broadcastsResponse['id'])); 

$video = $listResponse[0]['snippet']; 
$video['categoryId'] = $category; 

$updateResponse = $youtube->videos->update("snippet", $video); 

回答

2

您正在使用正确的资源,但以错误的方式的代码。

1)你应该先创建liveBroadcasts.insert()

2广播),然后用广播/视频ID您从操作得到,你调用该更新方法videos.update(),你可以设置类别。

pseudocode: 
response = livebroadcast -> insert(broadcast); 
video = new video(); 
video.id = response.broadcastId; 
video->setCategory(25); 
videos->update(video); 
+0

这解决了我的问题!谢谢! – DevStarlight