Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
设置live事件的contentDetails时出错-Youtube live API v3_Api_Post_Youtube_Youtube Api_Youtube Livestreaming Api - Fatal编程技术网

设置live事件的contentDetails时出错-Youtube live API v3

设置live事件的contentDetails时出错-Youtube live API v3,api,post,youtube,youtube-api,youtube-livestreaming-api,Api,Post,Youtube,Youtube Api,Youtube Livestreaming Api,一段时间以来,我一直在使用php成功创建yt live events。由于我尝试禁用嵌入,因此收到以下错误: ["Error calling POST https:\/\/www.googleapis.com\/youtube\/v3\/liveBroadcasts?part=snippet%2Cstatus: (400) contentDetails"] 代码如下: $client = new Google_Client();

一段时间以来,我一直在使用php成功创建yt live events。由于我尝试禁用嵌入,因此收到以下错误:

["Error calling POST https:\/\/www.googleapis.com\/youtube\/v3\/liveBroadcasts?part=snippet%2Cstatus: (400) contentDetails"]
代码如下:

                            $client = new Google_Client();
                            $client->setClientId($OAUTH2_CLIENT_ID);
                            $client->setClientSecret($OAUTH2_CLIENT_SECRET);


                            $client->refreshToken($tokens[0]['google_oauth_refresh_token']);


                            // Define an object that will be used to make all API requests.
                            $youtube = new Google_Service_YouTube($client);



                            // Check to ensure that the access token was successfully acquired.
                            if ($client->getAccessToken()) {    

                                            // die();


                                // Create an object for the liveBroadcast resource's snippet. Specify values
                                // for the snippet's title, scheduled start time, and scheduled end time.
                                $broadcastSnippet = new Google_Service_YouTube_LiveBroadcastSnippet();
                                $broadcastSnippet->setTitle($_POST['title']);
                                $broadcastSnippet->setDescription($_POST['description']);
                                $broadcastSnippet->setScheduledStartTime(date('c', strtotime($_POST['start_date']))); //'2034-01-30T00:00:00.000Z');
                                $broadcastSnippet->setScheduledEndTime(date('c', strtotime($_POST['start_time']))); // '2034-01-31T00:00:00.000Z');

                                $contentDetails = new Google_Service_YouTube_LiveBroadcastContentDetails();
                                $contentDetails->setEnableEmbed(false);
                                // debug($contentDetails);

                                // Create an object for the liveBroadcast resource's status, and set the
                                // broadcast's status to "private".
                                $status = new Google_Service_YouTube_LiveBroadcastStatus();
                                // $status->setPrivacyStatus('public');
                                $status->setPrivacyStatus('private');
                                // $status->setPrivacyStatus('unlisted');

                                // Create the API request that inserts the liveBroadcast resource.
                                $broadcastInsert = new Google_Service_YouTube_LiveBroadcast();
                                $broadcastInsert->setContentDetails($contentDetails);
                                $broadcastInsert->setSnippet($broadcastSnippet);
                                $broadcastInsert->setStatus($status);
                                $broadcastInsert->setKind('youtube#liveBroadcast');

                                // Execute the request and return an object that contains information
                                // about the new broadcast.
                                $broadcastsResponse = $youtube->liveBroadcasts->insert('snippet,status', $broadcastInsert, array());

                                // Create an object for the liveStream resource's snippet. Specify a value
                                // for the snippet's title.
                                $streamSnippet = new Google_Service_YouTube_LiveStreamSnippet();
                                $streamSnippet->setTitle('Transcoder - '.$_POST['title']);

                                // Create an object for content distribution network details for the live
                                // stream and specify the stream's format and ingestion type.
                                $cdn = new Google_Service_YouTube_CdnSettings();
                                $cdn->setFormat("720p");
                                $cdn->setIngestionType('rtmp');

                                // Create the API request that inserts the liveStream resource.
                                $streamInsert = new Google_Service_YouTube_LiveStream();
                                $streamInsert->setSnippet($streamSnippet);
                                $streamInsert->setCdn($cdn);
                                $streamInsert->setKind('youtube#liveStream');

                                // Execute the request and return an object that contains information
                                // about the new stream.
                                $streamsResponse = $youtube->liveStreams->insert('snippet,cdn',
                                    $streamInsert, array());

                                // debug($streamsResponse);

                                // Bind the broadcast to the live stream.
                                $bindBroadcastResponse = $youtube->liveBroadcasts->bind(
                                    $broadcastsResponse['id'],'id,contentDetails',
                                    array(
                                        'streamId' => $streamsResponse['id'],
                                    ));
在这方面:

$broadcastsResponse = $youtube->liveBroadcasts->insert('snippet,status', $broadcastInsert, array());
应该是:

$broadcastsResponse = $youtube->liveBroadcasts->insert('snippet,status,contentDetails', $broadcastInsert, array());
您正在设置contentDetails的嵌入属性,但未将其包含在请求中。 如果你读到错误,那就是它所抱怨的