manishnlet77 / laravel-youtube-publisher
A production-ready Laravel package for authenticated YouTube publishing (Video & Shorts) via Google OAuth 2.0.
Package info
github.com/manishnlet77/laravel-youtube-publisher
pkg:composer/manishnlet77/laravel-youtube-publisher
Requires
- php: ^8.1
- illuminate/console: ^10.0|^11.0|^12.0
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/http: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Laravel YouTube Publisher ๐
Upload Videos & Shorts via YouTube Data API v3
The ultimate Laravel package to automate YouTube video uploads, manage YouTube Shorts, set custom thumbnails, and handle Google OAuth 2.0 seamlessly.
<a href="https://packagist.org/packages/manishnlet77/laravel-youtube-publisher"><img src="https://img.shields.io/packagist/v/manishnlet77/laravel-youtube-publisher.svg?style=for-the-badge&logo=laravel" alt="Latest Version on Packagist"></a>
<a href="https://packagist.org/packages/manishnlet77/laravel-youtube-publisher"><img src="https://img.shields.io/packagist/dt/manishnlet77/laravel-youtube-publisher.svg?style=for-the-badge&color=success" alt="Total Downloads"></a>
<a href="https://php.net"><img src="https://img.shields.io/badge/PHP-8.1+-777BB4.svg?style=for-the-badge&logo=php" alt="PHP Version Requirement"></a>
<a href="https://laravel.com"><img src="https://img.shields.io/badge/Laravel-10.x|11.x-FF2D20.svg?style=for-the-badge&logo=laravel" alt="Laravel Framework Compatibility"></a>
Keywords: laravel youtube api, laravel youtube upload, youtube shorts api, laravel google oauth, youtube data api v3, laravel video upload, auto publish youtube
Perfect for CMS platforms, content creators, and agencies that need to auto-publish YouTube videos, manage playlists, set thumbnails, and keep tokens refreshed automatically in the background.
โจ Features
| Feature | Description |
|---|---|
| ๐ Bulk Uploads | Resumable chunked uploads for massive 10GB+ video files safely. |
| ๐ฑ YouTube Shorts | Explicit support and auto-tagging for YouTube Shorts API. |
| ๐ Auto Token Refresh | Authenticate once! The package refreshes your token in the background forever. |
| ๐ฎ Interactive Sandbox | A beautiful built-in web UI to test uploads instantly without writing code. |
| ๐ ๏ธ Diagnostic Tools | Built-in Artisan commands to safely test API quotas and connections. |
| ๐ผ๏ธ Playlists & Thumbs | Fluent API methods to set custom thumbnails and manage your playlists. |
๐ Zero to End Setup Guide
Follow these steps exactly to go from absolute zero to fully automated YouTube uploads!
๐ฆ Step 1: Installation
Install the package via Composer:
composer require manishnlet77/laravel-youtube-publisher
Run the database migrations. This creates a youtube_credentials table to securely store your OAuth tokens:
php artisan migrate
(Optional) Publish the configuration file:
php artisan vendor:publish --tag="youtube-publisher-config"
โ๏ธ Step 2: Google Cloud Setup
You must create an OAuth application in Google Cloud to get your API credentials.
- Go to the Google Cloud Console.
- Create a New Project.
- Go to APIs & Services -> Library, search for YouTube Data API v3, and click Enable.
- Go to Google Auth Platform -> Branding (or OAuth Consent Screen) and configure the consent screen.
- ๐ CRITICAL STEP FOR PRODUCTION:
- Go to Google Auth Platform -> Audience.
- Under "Publishing status", click Publish app to set it to "In production".
- (If you leave it in "Testing", Google will force your refresh token to expire every 7 days and your auto-uploads will break!)
- You do not need to submit it for verification if you are only uploading to your own channel.
- Go to APIs & Services -> Credentials.
- Click Create Credentials -> OAuth client ID.
- Application type: Web application
- Authorized redirect URIs: Add your application's callback URL (e.g.,
http://localhost:8000/youtube-publisher/callbackor your production URL).
- Copy the Client ID and Client Secret.
โ๏ธ Step 3: Environment Configuration
Add your Google credentials to your Laravel .env file:
YOUTUBE_PUBLISHER_CLIENT_ID="your-google-client-id" YOUTUBE_PUBLISHER_CLIENT_SECRET="your-google-client-secret" YOUTUBE_PUBLISHER_REDIRECT_URI="${APP_URL}/youtube-publisher/callback" # Enable this to use the built-in UI for testing! YOUTUBE_PUBLISHER_SANDBOX_ENABLED=true
๐ Step 4: Authentication & Sandbox
To upload videos, the package needs permission to access your YouTube channel.
- Ensure
YOUTUBE_PUBLISHER_SANDBOX_ENABLED=trueis in your.env. - Visit
/youtube-publisherin your browser (e.g.,http://localhost:8000/youtube-publisher). - Click the Connect YouTube button.
- Log in with your Google account. (If Google warns you that the app is unverified, click Advanced -> Go to App (unsafe)).
- You will be redirected back with a success message! Your token is now securely saved in the database.
๐งช Step 5: Test the Connection
We include a diagnostic Artisan command to ensure your API limits, tokens, and configurations are perfectly set up before you write any code. Run this command in your terminal:
php artisan youtube:test
Note: This will attempt to upload a tiny built-in dummy video as a Private video to your channel. If it succeeds, your integration is 100% ready!
๐ป Code Integration
You can now automate uploads anywhere in your Laravel app (Controllers, Jobs, Commands).
๐ฌ Uploading a Video or Short
use Manishnlet77\YouTubePublisher\Facades\YouTubePublisher; use Manishnlet77\YouTubePublisher\DTO\VideoMetadata; $absolutePath = storage_path('app/videos/my_video.mp4'); // 1. Prepare the Metadata $metadata = new VideoMetadata( title: "My Awesome Video", // REQUIRED description: "Video desc...", // REQUIRED hashtags: ['laravel', 'php'], // REQUIRED privacy: 'public' // Optional: 'public', 'private', or 'unlisted' ); // 2. Upload Normal Video $response = YouTubePublisher::videos()->upload($absolutePath, $metadata); // OR Upload YouTube Short // $response = YouTubePublisher::shorts()->upload($absolutePath, $metadata); echo "Uploaded! Video ID: " . $response['id'];
๐ผ๏ธ Setting a Thumbnail
$thumbnailPath = storage_path('app/images/thumb.jpg'); YouTubePublisher::thumbnails()->set('YOUTUBE_VIDEO_ID', $thumbnailPath);
๐ Managing Playlists
// Create a playlist $playlist = YouTubePublisher::playlists()->create( title: 'Laravel Tutorials', description: 'Learn Laravel', privacy: 'public' ); // Add a video to it YouTubePublisher::playlists()->addVideo($playlist['id'], 'YOUTUBE_VIDEO_ID');
๐ Troubleshooting & Common Errors
| Error | Cause & Solution |
|---|---|
quotaExceeded |
YouTube strictly limits API usage to 10,000 units per day. Uploading one video costs 1,600 units (approx. 6 videos a day). You must wait 24 hours or request a quota increase from Google. |
invalid_grant |
Your refresh token expired or was revoked. Visit /youtube-publisher and log in again. |
401 Unauthorized |
You did not enable the YouTube Data API v3 in your Google Cloud project. |
๐ License
MIT License.