2017-10-11 40 views
0

我已經可以在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']) 

回答

0

如果你讀了錯誤,它應該已經告訴你問題是什麼:

Call to undefined method Google_Service_YouTube_VideoSnippet::setScheduledStartTime()

看着LiveBroadcasts.update,有沒有這樣的方法setScheduledStartTime(看起來像你發明了它的飛行)。如果您想更新snippet.scheduledStartTime財產,你必須設置你的LiveBroadcasts.update請求的請求體。

+0

的問題是:「如何使用YouTube的PHP庫更新直播?」。我如何調用更新方法?我如何傳遞參數? –

+0

我不能爲你編寫代碼,因爲我不工作在PHP上。我希望你知道如何使用你的工具,而不是在xD上發明方法 – noogui

相關問題