php - 通过 API v3 上传到 YouTube 时“正在处理视频”
问题描述
我正在尝试将 mp4 格式的视频上传到 YouTube,并且正在使用开发人员页面中的代码。我尝试了很多,最终查看了源代码。现在我终于可以在我的创作者工作室看到一段视频了。问题是,它是一个黑色的缩略图,只是说正在处理,并且将永远保持这种状态(一周后没有完成)。我的视频长约 10 分钟,只有 13mb 左右,我怀疑我从谷歌页面获得的代码是旧的并且没有保持最新,这让我非常沮丧。
我尝试了不同的代码片段并编辑了参数。我的代码来自:https ://developers.google.com/youtube/v3/docs/videos/insert?apix=true
这是我目前的代码:
$client = new Google_Client();
$client->setApplicationName('API code samples');
$client->setScopes([
'https://www.googleapis.com/auth/youtube.upload'
]);
$client->setAuthConfig('assets/client_id.json');
$client->setAccessType('offline');
// Request authorization from the user.
$authUrl = $client->createAuthUrl();
printf("Open this link in your browser:\n%s\n", $authUrl);
print('Enter verification code: ');
$authCode = trim(fgets(STDIN));
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
$client->setAccessToken($accessToken);
// Define service object for making API requests.
$service = new Google_Service_YouTube($client);
// Define the $video object, which will be uploaded as the request body.
$video = new Google_Service_YouTube_Video();
// Add 'localizations' object to the $video object.
$localizations = new Google_Service_YouTube_VideoLocalization();
$video->setLocalizations($localizations);
$queryParams = [
'autoLevels' => true,
'notifySubscribers' => true,
'stabilize' => false,
'data' => file_get_contents("./content/$id/_$thread_name.mp4"),
'mimeType' => 'video/mp4',
'uploadType' => 'multipart'
];
$response = $service->videos->insert(
'snippet',
$video,
$queryParams
);
echo "https://youtu.be/".$response->id;
我希望我的代码能够运行,上传视频,然后给我一个链接。目前我没有收到任何错误,并且确实获得了链接。该链接只是没有显示工作视频。
我上传的示例视频(它们看起来都一样):https ://youtu.be/iOB_i-ZD5io
解决方案
推荐阅读
- sql - 引用列名而不是字段
- spring - 升级到 Spring Security 4 会中断登录
- docker - 来自 Dockerhub 注册表的 Kubernetes 部署中的图像拉取问题
- emacs - emacs 自动高亮 *E *F 等并高亮到 EOL
- mysql - 如何使用 case when 语句在列中设置 Mysql 加载的表项
- java - 如何避免事务被标记为只回滚;无法在异步任务中提交
- vb.net - 如何从 NuGet 包中引用 VB 中的模块
- angular8 - 错误:未捕获(承诺):ChunkLoadError:加载块 24 失败
- java - 非法选项:-cacerts for keytool in gitlab-ci with gradle:jdk8
- excel - 如果单元格 A = 是,如何删除单元格 B 中的值