how to upload video to vimeo in laravel
Recently one of our readers asked how to upload a video on YouTube from the Laravel application. They wanted to build a arrangement that tin upload YouTube videos from within the Laravel application. Doing so, they don't need to requite their YouTube account admission to the team members who manage the videos for the YouTube account.
In the past, I accept written an article which explains about upload video on YouTube using YouTube API in PHP. In this article, we will see how to upload a video on YouTube from the Laravel application.
Register an Application and Get Credentials
To go started, you need to have a Google Account. On the Google business relationship, you lot demand to register your awarding and get the API keys.
Beneath are the steps to register an application and take hold of the API keys.
- Become to the Google Developer Panel https://console.developers.google.com.
- Create a new project. You can also select existing project.
- Type a proper noun of your project. Google Console volition create unique project ID for yous.
- Upon creating a project, it will appear on top of the left sidebar.
- Click on Library from the left carte du jour. You lot will come across a list of Google APIs. Enable the YouTube Data API.
- Next, from the left menu click on the Credentials. Select Oauth Client id under Create credentials. Cull the radio push button for Spider web Application.
- Give the Proper name. Under Authorized JavaScript origins enter your domain URL. In the Authorized redirect URIs add the link of the redirect URL equally http://localhost:8000/youtube/callback. I am passing my local URL here. You should adapt this URL with your domain.
- Finally, click on the Create button. You volition become a customer ID and client secret in the pop-upwards. Copy these details. We will require information technology before long.
Install and Configure GitHub Library
Once you lot created the application, next matter need to do is install joedawson/youtube library. For installation of this library open up the last in your projection root directory and run the command:
composer require dawson/youtube
After installing the library, yous should annals the service provider and aliases in the config/app.php
file.
config/app.php
.... 'providers' => [ ... Dawson\Youtube\YoutubeServiceProvider::grade, ], .... 'aliases' => [ ... 'Youtube' => Dawson\Youtube\Facades\Youtube::course, ],
Next, publish the youtube.php
and migrations using the below command:
php artisan vendor:publish --provider="Dawson\Youtube\YoutubeServiceProvider"
The above command moves the file youtube.php
under 'config' folder and migration file nether 'database/migrations' binder. At present, you need to run the migration command which will create a table youtube_access_tokens
tabular array in the database.
php artisan drift
This table would shop the access token and refresh token after authorizing the YouTube account. The access_token is needed when you interact with the YouTube API. The access token acts every bit an identifier for your YouTube account. The access token has a brusk span of a lifetime so to become the new access token this library uses a refresh token. Yous don't need to worry about inserting these tokens in a table. The library will do it in the groundwork.
We have copied the API credentials that need to be put inside the Laravel awarding. Open up the .env
file and add your client id and client secret as follows:
GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET=
If you are making any changes in the environment file yous should articulate the configuration using the control:
php artisan config:clear
Dominance of Google Account
For security reasons, the routes to authorize the YouTube account with your Laravel application are disabled by default. Y'all will need to enable it from your config/youtube.php
. Open the config/youtube.php
and enable it by simply replacing false value with truthful.
... 'enabled' => truthful, //set it to 'false' after authorisation
You tin at present qualify your account using the YOUR_DOMAIN_URL/youtube/auth URL in the browser. It will redirect to the Google login page to authenticate your business relationship. Consummate the procedure. On successful hallmark, you will redirect dorsum to your Laravel application. Check the youtube_access_tokens
table and yous should see tokens inserted in the 'access_token' column. This is a ane time process. The library will automatically generate access_token in the background even if it is expired. The user does not need to authorize their business relationship once more.
Upload Video on YouTube Account in Laravel Awarding
At this stage, you are set up with the access token. Now create a form to browse the video file and send information technology to YouTube. Let's create a controller past running the below command.
php artisan make:controller VideoController --resource
Ascertain the routes for VideoController
as follows.
routes/web.php
<?php ... Road::resource('video', 'VideoController');
Create a view resources/views/video.blade.php
and add the below code in it.
<form action="{{ url('video') }}" method="postal service" enctype="multipart/form-data"> <p><input type="text" name="title" placeholder="Enter Video Title" /></p> <p><textarea name="description" cols="30" rows="10" placeholder="Video clarification"></textarea></p> <p><input type="file" name="video" /></p> <push button type="submit" class="btn btn-default">Submit</button> {{ csrf_field() }} </course>
Call this view file from the index
method of our controller.
public part index() { return view('video'); }
Now, when you visit YOUR_DOMAIN_URL/video you will see a form that contains file input, championship, description, and submit button.
In order to phone call the YouTube API add together a YouTube class in a controller. And in the store
method write the code for uploading a video on YouTube as follows.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Youtube; class VideoController extends Controller { .... public function store(Request $request) { $video = Youtube::upload($request->file('video')->getPathName(), [ 'title' => $request->input('championship'), 'description' => $request->input('clarification') ]); return "Video uploaded successfully. Video ID is ". $video->getVideoId(); } }
Here nosotros are passing a video file, title, and description from our grade. This code merely uploads your video on YouTube and prints the YouTube video id.
I hope you lot understand about uploading a video on YouTube in the Laravel application. The user can also update and delete the videos using the lawmaking provided by the library. Y'all may read more about it on their documentation.
Related Manufactures
- PayPal Payments Pro Integration in Laravel
- How to Create a Weblog with Laravel
- How to Upload and Ingather Images in Laravel
If you lot liked this article, then please subscribe to our YouTube Channel for video tutorials.
Source: https://artisansweb.net/how-to-upload-video-on-youtube-in-laravel-application/
0 Response to "how to upload video to vimeo in laravel"
Postar um comentário