我已经可以在YouTube直播创建广播事件,现在我试图修改与更新API现有的。Youtube API - PHP - 如何修改现有广播的开始时间?
的问题是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");
}
}
它引发此错误:
致命错误:调用未定义方法Google_Service_YouTube_VideoSnippet :: setScheduledStartTime()中/var/www/html/production/app/empowerir/php/videoStreaming/functions.php上线242
线242是:
$videoSnippet->setScheduledStartTime($streamData['eventDateTime'])
的问题是:“如何使用YouTube的PHP库更新直播?”。我如何调用更新方法?我如何传递参数? –
我不能为你编写代码,因为我不工作在PHP上。我希望你知道如何使用你的工具,而不是在xD上发明方法 – noogui