【发布时间】:2021-06-15 12:29:37
【问题描述】:
我正在使用 Google API 创建 YouTube 直播。并成功创建。 它的默认流选项类型是“流媒体软件”
我需要将其更改为“内置网络摄像头”
我正在使用this使用PHP来实现。
$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$client->setScopes('https://www.googleapis.com/auth/youtube');
$client->setAccessToken($accessToken);
try {
// Define service object for making API requests.
$service = new Google_Service_YouTube($client);
// Define the $liveBroadcast object, which will be uploaded as the request body.
$liveBroadcast = new Google_Service_YouTube_LiveBroadcast();
// Add 'contentDetails' object to the $liveBroadcast object.
$liveBroadcastContentDetails = new Google_Service_YouTube_LiveBroadcastContentDetails();
$liveBroadcastContentDetails->setEnableClosedCaptions(true);
$liveBroadcastContentDetails->setEnableContentEncryption(true);
$liveBroadcastContentDetails->setEnableDvr(true);
// $liveBroadcastContentDetails->setEnableEmbed(true);
$liveBroadcastContentDetails->setRecordFromStart(true);
$liveBroadcastContentDetails->setStartWithSlate(true);
$liveBroadcast->setContentDetails($liveBroadcastContentDetails);
// Add 'snippet' object to the $liveBroadcast object.
$liveBroadcastSnippet = new Google_Service_YouTube_LiveBroadcastSnippet();
$liveBroadcastSnippet->setScheduledStartTime($start_date_time);
$liveBroadcastSnippet->setTitle($class_name);
$liveBroadcast->setSnippet($liveBroadcastSnippet);
// Add 'status' object to the $liveBroadcast object.
$liveBroadcastStatus = new Google_Service_YouTube_LiveBroadcastStatus();
$liveBroadcastStatus->setPrivacyStatus('unlisted');
$liveBroadcast->setStatus($liveBroadcastStatus);
$response = $service->liveBroadcasts->insert('snippet,contentDetails,status', $liveBroadcast);
return ($response->id);
} catch (Google_Service_Exception $e) {
return;
} catch (Google_Exception $e) {
return;
}
【问题讨论】:
标签: php google-api youtube-data-api