Как я могу обновить видео YouTube? | PHP - PullRequest
0 голосов
/ 30 апреля 2018

Я пытаюсь обновить видео YouTube. Я использую функцию на сайте https://developers.google.com/youtube/v3/code_samples/php#update_a_video и пытаюсь скопировать ее в свой код, но если я вызываю listVideos (), я получаю Google_Service_YouTube_VideoListResponse, но мне нужен Google_Service_YouTube_Video. Как я могу получить это?

Мой код PHP:

$youtube = new Google_Service_YouTube($client);
$videoid = "******Video ID********";
$new = "******* TEXT *********";
$videoinfo = $youtube->videos->listVideos('snippet', array('id' => $videoid));
$videoSnippet = $videoinfo[0]['snippet'];
$description = $videoSnippet['description'] . $new;
$videoSnippet['description'] = $description;
$youtube->videos->update("snippet", $videoSnippet);

Ошибка:

: Uncaught TypeError: Argument 2 passed to 
Google_Service_YouTube_Resource_Videos::update() must be an instance of 
Google_Service_YouTube_Video, instance of 
Google_Service_YouTube_VideoSnippet given, called in 
P:\Apache24\htdocs\*********** on line 232 and defined in 
P:\Apache24\htdocs\*******\Google Api System\vendor\google\apiclient- 
services\src\Google\Service\YouTube\Resource\Videos.php:309 
Stack trace:
0 P:\Apache24\htdocs\*********: Google_Service_YouTube_Resource_Videos- 
>update('snippet', Object(Google_Service_YouTube_VideoSnippet ))
1 P:\Apache24\htdocs\********\*********\index.php(438): 
require('P:\\Apache24\\htd...')

1 Ответ

0 голосов
/ 30 апреля 2018

вы должны использовать

  $video = $listResponse[0];
  $updateResponse = $youtube->videos->update("snippet", $video);

, поскольку в документации

// Since the request specified a video ID, the response only
      // contains one video resource.
      $video = $listResponse[0];
      $videoSnippet = $video['snippet'];
      $tags = $videoSnippet['tags'];

      // Preserve any tags already associated with the video. If the video does
      // not have any tags, create a new list. Replace the values "tag1" and
      // "tag2" with the new tags you want to associate with the video.
      if (is_null($tags)) {
        $tags = array("tag1", "tag2");
      } else {
        array_push($tags, "tag1", "tag2");
      }

      // Set the tags array for the video snippet
      $videoSnippet['tags'] = $tags;

      // Update the video resource by calling the videos.update() method.
      $updateResponse = $youtube->videos->update("snippet", $video);
...