I am trying to upload a video in mp4 format to YouTube and am using code from the developer page. I tried so much and eventually looked into the source code. Now I am finally at a point where I see a video in my creator studio. Problem is, it's a black thumbnail and just says processing and will forever stay in that state (Didn't finish a week later). My videos are about 10 min long, only 13mb or so big and I suspect that the code I got from the google page is old and has not been held up to date, which makes me really frustrated.
I tried different code snippets and edited the parameters. I got my code from: https://developers.google.com/youtube/v3/docs/videos/insert?apix=true
This is my code at the moment:
$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:
%s
", $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;
I am expecting my code to run, upload the video and give me a link afterwards. At this moment I don't get any errors and I do get a link. The link just doesn't show a working video.
Example video I uploaded (all of them look the same): https://youtu.be/iOB_i-ZD5io