gpt4 book ai didi

php - 未捕获的异常 'Google_Service_Exception',显示消息“调用PUT时出错

转载 作者:行者123 更新时间:2023-12-03 05:37:44 28 4
gpt4 key购买 nike

我编写了一个脚本,使用其API将多个视频上传到YouTube。

问题是,当我运行脚本时,它会上传第一个视频,但是在第二次迭代中,它无法正确上传视频并引发异常:

 PHP Fatal error:  Uncaught exception 'Google_Service_Exception' with
message 'Error calling PUT
https://www.googleapis.com/upload/youtube/v3/videos?part=status%2Csnippet&uploadType=resumable&upload_id=AEnB2Uov0hJdmXu0UKN65WejqwsCvdhkXuIxgftiNPfNQYRv2MLwWaqSDHBlq5rUmn7xLwAl7ZXdbK8YcFprx_6uao8of119Fw:
(400) Failed to parse Content-Range header.' in
/var/www/html/YoutubeApi/Google/Http/REST.php:80 Stack trace:
#0 /var/www/html/YoutubeApi/Google/Http/MediaFileUpload.php(185): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request))
#1 /var/www/html/YoutubeApi/upload_video.php(79): Google_Http_MediaFileUpload->nextChunk('E(?03?F????N???...')
#2 /var/www/html/YoutubeApi/upload_video.php(272): UploadVideo->upload_video('Ireland Video W...', 'Welcome to Tour...',
'/var/www/html/Y...', Array)
#3 /var/www/html/YoutubeApi/upload_video.php(28): UploadVideo->run()
#4 /var/www/html/YoutubeApi/upload_video.php(308): UploadVideo->__construct()
#5 {main} thrown in /var/www/html/YoutubeApi/Google/Http/REST.php on line 80

这是我的脚本:
private function run() {
$dir = "";
$videos = $arr = $this->get_active_videos();
$directory = __DIR__ . "/temp/";
if (!file_exists($directory)) {
$dir = mkdir(__DIR__ . "/temp", 0777);
}

$this->youtube_client->setAccessToken($this->get_access_token(1));
if ($this->youtube_client->getAccessToken()) {
foreach ($videos as $video) {
$this->set_youtube_video_obj();
//$channels = explode(",", $video['channel']);
if (!strlen($video['category']) && !strlen($video['channel'])) {
continue;
}
file_put_contents("temp/video", file_get_contents($video['media_link']));
sleep(5);
$tags = $this->get_video_tags($video['location'], $video['event'], $video['country'], $video['video_cat']);
$status = $this->upload_video($video['title'], $video['description'], $directory . "/video", $tags);
if ($status['status']['uploadStatus'] == 'uploaded') {
if (strlen($video['category'])) {
$categories = explode(",", $video['category']);
// $video_files = $this->get_files();
foreach ($categories as $category) {
$playlists = $this->get_playlists(1);
//foreach ($playlists as $playlist) {
$cat_name = $this->get_category_name($category);
$this->add_video_to_playlist($status, $video['title'], $video['description'], $cat_name);
sleep(3);
}
} else if (strlen($video['channel'])) {
$tags = $this->get_video_tags($video['location'], $video['event'], $video['country'], $video['video_cat']);
$status = $this->upload_video($video['title'], $video['description'], $directory . "/video", $tags);
$channels = explode(",", $video['channel']);
//$video_files = $this->get_files();
//foreach ($video_files as $video_file) {
foreach ($channels as $channel) {
if ($status['status']['uploadStatus'] == 'uploaded') {
$channel_name = $this->get_channel_name($channel);
$category_name = $this->get_playlist_from_channel($channel_name);
$this->add_video_to_playlist($status, $video['title'], $video['description'], $category_name);
}
}
//}
}
}

$this->unset_youtube_video_obj();
}
}
}

}

我已经尝试了很多东西,但无济于事,谢谢任何帮助。

最佳答案

我遇到同样的错误,我发现视频文件夹为空
所以我认为您的问题与您无法正确设置视频路径有关

关于php - 未捕获的异常 'Google_Service_Exception',显示消息“调用PUT时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35884950/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com