您好,我在尝试使用 youtube api 更新标签时不断收到此致命错误。我错过了什么吗?谢谢
这是我不断收到的错误 -
Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling PUT https://www.googleapis.com/youtube/v3/videos?part=snippet&key=AIzaSyAtyCr7wQNuQU-4eXYToN2rv0fMR6TsR8Y: (400) Bad Request' in C:\xampp\htdocs\x\includes\google-api-php-client\src\io\Google_REST.php:66Stack trace:#0 C:\xampp\htdocs\x\includes\google-api-php-client\src\io\Google_REST.php(36):
Google_REST::decodeHttpResponse(Object(Google_HttpRequest))#1 C:\xampp\htdocs\x\includes\google-api-php-client\src\service\Google_ServiceResource.php(186):
Google_REST::execute(Object(Google_HttpRequest))#2 C:\xampp\htdocs\x\includes\google-api-php-client\src\contrib\Google_YouTubeService.php(952): Google_ServiceResource->__call('update', Array)#3 C:\xampp\htdocs\x\includes\insert_tags.php(68):
Google_VideosServiceResource->update('snippet', Object(Google_Video))#4 {main} thrown in C:\xampp\htdocs\x\includes\google-api-php-client\src\io\Google_REST.php on line 66
<?php
if(isset($_GET['insertTags']))
{
require_once 'channelHeaders.php';
$postdata = file_get_contents("php://input"); // to get POST data from angular $http
$request = json_decode($postdata,true); // to convert POST data to array
// $videoId = $request['video_id'];
// $tagsToBeAdded = $request['new_tags'];
echo $request['video_id'];
echo $request['new_tags'];
echo "<br/>";
$videoId = $request['video_id'];
// Create a video list request
$listResponse = $youtube->videos->listVideos('id,snippet', array(
'id' => $videoId
));
$videoList = $listResponse['items'];
//var_dump($videoList);
if (empty($videoList)) {
echo "Video does not exist.";
} else {
// Since a unique video id is given, it will only return 1 video.
$video = $videoList[0];
$videoSnippet = $video['snippet'];
$tags = $videoSnippet['tags'];
//var_dump($tags);
}
if (is_null($tags)) {
// $tags = array("metal", "even");
$tags = array($request['new_tags']);
echo "NULL";
} else {
echo "NOT NULL<br/>";
array_push($tags, $request['new_tags']);
// array_push($tags, "metal", "even");
// Construct the Google_Video with the updated tags, hence the snippet
$updateVideo = new Google_Video($video);
$updateSnippet = new Google_VideoSnippet($videoSnippet);
$updateSnippet->setTags($tags);
$updateVideo -> setSnippet($updateSnippet);
// Create a video update request
//ERROR COMES FROM THESE 2 LINES BELOW
$updateResponse = $youtube->videos->update("snippet", $updateVideo);
$responseTags = $updateResponse['snippet']['tags'];
echo "success";
}
}
我已经尝试了很多东西但无济于事,任何帮助将不胜感激谢谢