Reputation: 804
I'm trying to define a category for a Youtube broadcast before the livestream is on air.
I've just followed Youtube API documentation and I didn't find any snipped definition for setCategory
method in any class related to broadcasting or livestreaming.
According to that, the only way I've found to define a category is by creating a Google_Service_YouTube_VideoSnippet
object. Something like this:
$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);
Here I let a link with the code that makes all the work:
What Am I doing wrongly? Is it a bug?
Thanks in advice.
UPDATE
Here bellow I paste the code that helped me solving this problem
$listResponse = $youtube->videos->listVideos("snippet",
array('id' => $broadcastsResponse['id']));
$video = $listResponse[0]['snippet'];
$video['categoryId'] = $category;
$updateResponse = $youtube->videos->update("snippet", $video);
Upvotes: 2
Views: 874
Reputation: 12877
You are using the right resource but in a wrong way.
1) you should first create the broadcast with liveBroadcasts.insert()
2) Then with the broadcast/video id you get from that operation, you call videos.update() in that update method, you can set the category.
pseudocode:
response = livebroadcast -> insert(broadcast);
video = new video();
video.id = response.broadcastId;
video->setCategory(25);
videos->update(video);
Upvotes: 2