【发布时间】:2017-10-11 19:45:58
【问题描述】:
我已经可以在 YouTube Live 中创建广播事件,现在我正在尝试使用更新 API 修改现有事件。
问题是 VideoSnippet 库不允许这样做,必须以其他方式完成。
(这个PHP函数将由前端通过ajax请求调用)
function updateBroadcast(){
if(!isset($client)){
$client = getClient();
}
$streamData = $_POST['streamData'];
$client->setAccessToken($_SESSION['google_access_token']);
$service = new Google_Service_YouTube($client);
if ($client->getAccessToken()) {
try {
$videoId = $streamData['id'];
// Call the API's videos.list method to retrieve the video resource.
$listResponse = $service->videos->listVideos("snippet",
array('id' => $videoId));
if (empty($listResponse)) {
return json_encode(sprintf('Can\'t find a video with video id: %s', $videoId));
} else {
// Since the request specified a video ID, the response only
// contains one video resource.
$video = $listResponse[0];
$videoSnippet = $video['snippet'];
$videoSnippet->setTitle($streamData['eventName']);
$videoSnippet->setDescription($streamData['eventCategory']);
$videoSnippet->setScheduledStartTime($streamData['eventDateTime'])
}
} catch (Google_Service_Exception $e) {
echo sprintf('<p>A service error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
echo sprintf('<p>An client error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}
return json_encode("Video Updated");
}
}
它会抛出这个错误:
致命错误:在第 242 行的 /var/www/html/production/app/empowerir/php/videoStreaming/functions.php 中调用未定义的方法 Google_Service_YouTube_VideoSnippet::setScheduledStartTime()
第 242 行是:
$videoSnippet->setScheduledStartTime($streamData['eventDateTime'])
【问题讨论】:
标签: php youtube-api