Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.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
如何更新YouTube视频PHP_Php_Youtube_Youtube Api_Youtube Data Api - Fatal编程技术网

如何更新YouTube视频PHP

如何更新YouTube视频PHP,php,youtube,youtube-api,youtube-data-api,Php,Youtube,Youtube Api,Youtube Data Api,我尝试更新YouTube视频。我在网站上使用该函数,并尝试在代码中复制该函数,但如果调用listVideos(),我会得到Google\u服务\u YouTube\u视频列表响应,但我需要Google\u服务\u YouTube\u视频。我怎样才能得到它 我的PHP代码: $youtube = new Google_Service_YouTube($client); $videoid = "******Video ID********"; $new = "******* TEXT *******

我尝试更新YouTube视频。我在网站上使用该函数,并尝试在代码中复制该函数,但如果调用listVideos(),我会得到Google\u服务\u YouTube\u视频列表响应,但我需要Google\u服务\u YouTube\u视频。我怎样才能得到它

我的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...')
你必须使用

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


$videoid=“*******视频ID*******;您忘记用“$videoid=“*******视频ID**********””结束@g33k我只是在stackoverflow中忘了:)在我的代码中我写$videoid=“*******视频ID*******”;是
$videoid
字面意思是
******************
还是它也在这里?!然后我得到了错误“code”:400,“message”:“请求元数据无效”。但我认为这是正确的方法:)错误:{“Error”:{“errors”:[{“domain”:“youtube.video”,“reason”:“invalidVideoMetadata”,“message”:“请求元数据无效”。,“locationType”:“other”,“location”:“body”}],“code”:400,“message”:“请求元数据无效。”}}}是否执行该操作//检查所需作用域$tokenSessionKey='token-'。$client->prepareScopes()是否存在身份验证令牌;//创建具有标题、说明、标记和类别ID的片段//创建资产资源并设置其片段元数据和类型//此示例设置视频的标题、说明、关键字标记和//视频类别。$snippet=new Google_Service_YouTube_VideoSnippet();$snippet->setTitle(“测试标题”);$snippet->setDescription(“测试描述”);$snippet->setTags(数组(“tag1”、“tag2”);检查
// 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);