Panduan API Key untuk Upload Video
Agar fitur Merge & Upload bisa mengirim video ke Google Drive dan YouTube, Anda perlu menyiapkan credentials berikut dan mengisinya di .env aplikasi Laravel.
1. Google Cloud Project (untuk Drive & YouTube)
Satu project dipakai untuk Google Drive API dan YouTube Data API v3.
- Buka Google Cloud Console.
- Buat project baru atau pilih project yang ada.
- Aktifkan 2 API:
- Google Drive API (untuk upload file ke Drive)
- YouTube Data API v3 (untuk upload video ke YouTube)
- Buat OAuth 2.0 Client ID:
- APIs & Services → Credentials → Create Credentials → OAuth client ID.
- Application type: Desktop app (atau Web application jika Anda punya redirect URI).
- Download JSON credentials. Dari sana Anda dapat
client_iddanclient_secret.
- Dapatkan Refresh Token (sekali saja):
- Gunakan OAuth 2.0 Playground (developers.google.com/oauthplayground) atau script kecil yang memanggil endpoint OAuth.
- Scope yang perlu:
https://www.googleapis.com/auth/drive.file(Drive),https://www.googleapis.com/auth/youtube.upload(YouTube). - Setelah authorize, tukar authorization code dengan refresh token. Simpan refresh token di .env.
2. Variabel .env untuk Google Drive
GOOGLE_DRIVE_UPLOAD_ENABLED=true
GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com
GOOGLE_DRIVE_CLIENT_SECRET=xxx
GOOGLE_DRIVE_REFRESH_TOKEN=xxx
GOOGLE_DRIVE_FOLDER_ID=optional_id_folder_tujuan
Jika GOOGLE_DRIVE_FOLDER_ID dikosongkan, file akan masuk ke root Drive. Untuk dapat folder ID: buka folder di drive.google.com, lihat URL, bagian setelah /folders/ adalah folder ID.
3. Variabel .env untuk YouTube
YOUTUBE_UPLOAD_ENABLED=true
YOUTUBE_CLIENT_ID=xxx.apps.googleusercontent.com
YOUTUBE_CLIENT_SECRET=xxx
YOUTUBE_REFRESH_TOKEN=xxx
Bisa memakai OAuth client yang sama dengan Google Drive (satu client_id/secret/refresh_token) asalkan scope OAuth sudah include youtube.upload. Jika memakai satu set credentials untuk keduanya, isikan nilai yang sama di blok Google Drive dan YouTube.
Ringkasan API / Credentials yang dibutuhkan
- Google Cloud Project dengan Drive API + YouTube Data API v3 enabled.
- OAuth 2.0 Client ID (Desktop atau Web) →
client_id&client_secret. - Refresh token dari alur OAuth (authorize sekali, dapat refresh token untuk dipakai berulang).
- Google Drive:
GOOGLE_DRIVE_*di .env. - YouTube:
YOUTUBE_*di .env (boleh sama dengan Drive bila satu OAuth client).
Setelah .env diisi dan php artisan config:cache dijalankan, proses Merge & Upload akan memakai kredensial tersebut. Implementasi upload ke Drive/YouTube di backend saat ini masih placeholder; setelah credentials siap, developer dapat menambahkan pemanggilan Google Drive API (resumable upload) dan YouTube Data API v3 (videos.insert).