首页 > 解决方案 > 通过 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

标签: phpyoutube-data-api

解决方案


推荐阅读