Integrate youtube upload video in Laravel
Posted By : Vishal Yadav | 13-Apr-2020
In this tutorial we will talk about uploading videos in single youtube channel(account) not multiple.
Pull the following package from github via composer
composer require dawson/youtube
Register in the service provider in `config/app.php`
'providers' => [ ... Dawson\Youtube\YoutubeServiceProvider::class, ],
Add alias for same provider with in the same file.
'aliases' => [ ... 'Youtube' => Dawson\Youtube\Facades\Youtube::class, ],
Configuration
Publish youtube.php config file and migrate.
php artisan vendor:publish --provider="Dawson\Youtube\YoutubeServiceProvider"
For migration use the artisan migrate command to generate table to store youtube access tokens
php artisan migrate
Obtaining credentials
To abtain the access make changes in config/youtube.php
change enabled to true to access the youtube auth url. By default auth url is disabled because of security issue.
Visit to your google app and copy the client_id and secreat code.
Put same on your .env file as
GOOGLE_CLIENT_ID=YOUR_CLIENT_ID
GOOGLE_CLIENT_SECRET=YOUR_SECRET
Add http://YOUR_SITE_URL/youtube/callback in your app auth urls.
Visit to page http://YOUR_SITE_URL/youtube/auth to link the youtube channel to your site.
Hurry, thats it. Create a controller in Laravel and use below code to upload video to youtube channel.
use Youtube;
..
..
..
$fullPathToVideo = storage_path('app/public/video.mp4');
$video = Youtube::upload($fullPathToVideo, [ 'title' => 'My Video', 'description' => 'Video description here.', 'tags' => ['some', 'tags', 'here'], 'category_id' => 7 ]); return $video->getVideoId();
In order to delete the video use
Youtube::delete($videoId);
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Vishal Yadav
Vishal is a backend developer with good knowledge of WordPress, Codeigniter and js/jQuery. He likes to learn new technologies and play video games.