2017 © Pedro Peláez
 

library youtube

Upload a video to YouTube with Laravel 5.

image

schooch/youtube

Upload a video to YouTube with Laravel 5.

  • Tuesday, May 29, 2018
  • by schooch
  • Repository
  • 1 Watchers
  • 0 Stars
  • 580 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 50 Forks
  • 0 Open issues
  • 26 Versions
  • 150 % Grown

The README.md

Laravel 5 - YouTube Video Upload - Forked from JoeDawson

Please note, that this package will only work with a single YouTube account and does not support multiple accounts., (*1)

Installation

To install, use the following to pull the package in via Composer., (*2)

composer require schooch/youtube

Now register the Service provider in config/app.php, (*3)

'providers' => [
    ...
    schooch\Youtube\YoutubeServiceProvider::class,
],

And also add the alias to the same file., (*4)

'aliases' => [
    ...
    'Youtube' => schooch\Youtube\Facades\Youtube::class,
],

Configuration

You now need to publish the youtube.php config and migrations., (*5)

php artisan vendor:publish --provider="schooch\Youtube\YoutubeServiceProvider"

Now you'll want to run php artisan migrate to create the youtube_access_tokens table which as you would imagine, will contain your access tokens once you're authenticated correctly., (*6)

Obtaining your Credentials

If you haven't already, you'll need to create an application on Google's Developer Console. You then need to head into Credentials within the Console to create Server key., (*7)

You will be asked to enter your Authorised redirect URIs. When installing this package, the default redirect URI is http://laravel.dev/youtube/callback. Of course, replacing the domain (laravel.dev) with your applications domain name., (*8)

You can add multiple redirect URIs, for example you may want to add the URIs for your local, staging and production servers., (*9)

Once you are happy with everything, create the credentials and you will be provided with a Client ID and Client Secret. These now need to be added to your .env file., (*10)

GOOGLE_CLIENT_ID=YOUR_CLIENT_ID
GOOGLE_CLIENT_SECRET=YOUR_SECRET

Authentication

For security reasons, the routes to authorize your channel with your Laravel application for disabled by default. You will need to enable them in your config/youtube.php before doing the following., (*11)

Now your application is configured, we'll go through the inital authentication with Google. By default, the authorization route is /youtube/auth. Simply visit this URI in your application and you will be redirect to Google to authenticate your YouTube account., (*12)

Assuming you were not presented with any errors during authentication, you will be redirected back to your application root. (/)., (*13)

Reviewing your Token

Previously, users of this package have reported issues with their access token(s). To ensure you have the correct token, you simply need to review the youtube_access_tokens table you migrated earlier and review the value in the access_token column., (*14)

You need to check that a refresh_token exists within this value. If this is correct, you're all set to begin uploading., (*15)

You will also want to disable the routes used for authorization as they will no longer be required since you are now autheticated. The token you just reviewed, assuming as a refresh_token will automatically be handled., (*16)

Upload a Video

To upload a video, you simply need to pass the full path to your video you wish to upload and specify your video information., (*17)

Here's an example:, (*18)

$video = Youtube::upload($fullPathToVideo, [
    'title'       => 'My Awesome Video',
    'description' => 'You can also specify your video description here.',
    'tags'        => ['foo', 'bar', 'baz'],
    'category_id' => 10
]);

return $video->getVideoId();

The above will return the ID of the uploaded video to YouTube. (i.e dQw4w9WgXcQ), (*19)

By default, video uploads are public. If you would like to change the privacy of the upload, you can do so by passing a third parameter to the upload method., (*20)

For example, the below will upload the video as unlisted., (*21)

$video = Youtube::upload($fullPathToVideo, $params, 'unlisted');

Custom Thumbnail

If you would like to set a custom thumbnail for for upload, you can use the withThumbnail() method via chaining., (*22)

$fullpathToImage = storage_path('app/public/thumbnail.jpg');

$video = Youtube::upload($fullPathToVideo, $params)->withThumbnail($fullpathToImage);

return $youtube->getThumbnailUrl();

Please note, the maxiumum filesize for the thumbnail is 2MB. Setting a thumbnail will not work if you attempt to use a thumbnail that exceeds this size., (*23)

Deleting a Video

If you would like to delete a video, which of course is uploaded to your authorized channel, you will also have the ability to delete it:, (*24)

Youtube::delete($videoId);

When deleting a video, it will check if exists before attempting to delete., (*25)

Questions

Should you have any questions, please feel free to submit an issue., (*26)

The Versions

29/05 2018

dev-master

9999999-dev

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson
by Ian Lainchbury

29/05 2018

v5.0.5

5.0.5.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson
by Ian Lainchbury

17/05 2018

v5.0.4

5.0.4.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson
by Ian Lainchbury

13/04 2018

v5.0.3

5.0.3.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson
by Ian Lainchbury

11/04 2018

v5.0.2

5.0.2.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson
by Ian Lainchbury

04/04 2018

v5.0.1

5.0.1.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson
by Ian Lainchbury

26/03 2018

5.0.0

5.0.0.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson
by Ian Lainchbury

21/03 2018

4.1.1

4.1.1.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson
by Ian Lainchbury

25/09 2017

4.1.0

4.1.0.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson

05/08 2017

dev-dev

dev-dev

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson

05/08 2017

3.1.2-beta

3.1.2.0-beta

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson

05/08 2017

4.0.0

4.0.0.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson

05/08 2017

3.1.0-beta

3.1.0.0-beta

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson

01/08 2017

3.0.3

3.0.3.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson

01/08 2017

3.1.1-beta

3.1.1.0-beta

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson

26/07 2017

3.0.2

3.0.2.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson

08/07 2017

3.0.1

3.0.1.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson

08/07 2017

3.0.0

3.0.0.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson

05/03 2017

2.0.1

2.0.1.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson

06/02 2017

v2.0.0

2.0.0.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joe Dawson

28/08 2016

1.1.2

1.1.2.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

by Joe Dawson

28/08 2016

1.1.1

1.1.1.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

by Joe Dawson

28/08 2016

1.1.0

1.1.0.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

by Joe Dawson

19/09 2015

1.1.0-beta

1.1.0.0-beta

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

by Joe Dawson

09/06 2015

1.0.2

1.0.2.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

by Joe Dawson

25/05 2015

1.0.1

1.0.1.0

Upload a video to YouTube with Laravel 5.

  Sources   Download

MIT

The Requires

 

by Joe Dawson