I'm working on a project where I would like to use WebRTC to record a video from my PHP website and upload it to my YouTube channel. For the code below I am just trying to get an upload to work, as the video is saved on my server. I'm not clear on what kind of key or authorization I need to use. After reading and studying the documentation, I think I need to use a service account (key) to accomplish this? https://developers.google.com/api-client-library/php/auth/service-accounts
I do not want users to log in/authenticate a google account. I would like the upload to happen from my website to my YouTube channel.
I don't have access to install with composer, so I have uploaded the google-api-php-client (v2.2.2) folder on my server.
I haven't been able to find any current examples that are closer to what I need, so I'm trying to mashup these pieces:
Uploads to Drive: https://developers.google.com/api-client-library/php/guide/media_upload Uses the Service Account key(?): https://developers.google.com/api-client-library/php/auth/service-accounts Upload Video: https://developers.google.com/youtube/v3/code_samples/php#upload_a_video
I'm getting Any guidance is appreciated. I am receiving a "This page isn't working" HTTP ERROR 500
Here is what my code currently looks like:
<?php
if (!file_exists('google-api-php-client/vendor/autoload.php')) {
throw new \Exception('please run "composer require google/apiclient:~2.0" in "' . __DIR__ .'"');
}
require_once 'google-api-php-client/vendor/autoload.php';
session_start();
putenv('GOOGLE_APPLICATION_CREDENTIALS=I-Video/i-video-recording-0e9cbc2cad7a.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$file = new Google_Service_YouTube($client);
$result = $service->files->insert($file, array(
'data' => file_get_contents("data/1530103005236.webm"),
'mimeType' => 'application/octet-stream',
'uploadType' => 'media'
));
?>