Looking to hire Laravel developers? Try LaraJobs

laravel-youtube-publisher maintained by manishnlet77

Description
A production-ready Laravel package for authenticated YouTube publishing (Video & Shorts) via Google OAuth 2.0.
Author
Last update
2026/09/19 08:32 (dev-master)
License
Links
Downloads
30

Comments
comments powered by Disqus
<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.

  1. Go to the Google Cloud Console.
  2. Create a New Project.
  3. Go to APIs & Services -> Library, search for YouTube Data API v3, and click Enable.
  4. Go to Google Auth Platform -> Branding (or OAuth Consent Screen) and configure the consent screen.
  5. 🛑 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.
  6. Go to APIs & Services -> Credentials.
  7. 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/callback or your production URL).
  8. 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.

  1. Ensure YOUTUBE_PUBLISHER_SANDBOX_ENABLED=true is in your .env.
  2. Visit /youtube-publisher in your browser (e.g., http://localhost:8000/youtube-publisher).
  3. Click the Connect YouTube button.
  4. Log in with your Google account. (If Google warns you that the app is unverified, click Advanced -> Go to App (unsafe)).
  5. 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.