Edit file File name : TROUBLESHOOT_GOOGLE_DRIVE.md Content :# Google Drive Authorization Troubleshooting ## Quick Check Commands Run these on your VPS to diagnose the issue: ### 1. Check if Google Drive is configured in .env ```bash grep GOOGLE /path/to/.env ``` Should output: ``` GOOGLE_CLIENT_ID=270248718468-iqtrb096khdn0kd6udutvkk56h3p3fgb.apps.googleusercontent.com GOOGLE_CLIENT_SECRET=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 GOOGLE_REDIRECT_URI=https://backup.alkashier.com/google-drive/callback ``` ### 2. Check if database is empty (no authorization yet) ```bash php artisan tinker >>> \App\Models\GoogleDriveSetting::count() # If returns 0 or 1, check the details: >>> \App\Models\GoogleDriveSetting::first() # Look for: 'is_connected' => false (if no authorization) ``` ### 3. Check stored tokens ```bash php artisan tinker >>> $setting = \App\Models\GoogleDriveSetting::first() >>> $setting->access_token # Should be a long string if authorized >>> $setting->is_connected # Should be 1/true if authorized >>> $setting->email # Should show authorized Gmail ``` ### 4. Test the authorization flow ```bash php artisan tinker >>> $service = new \App\Services\GoogleDriveService() >>> $service->isConnected() # Returns: true or false ``` ## What Should Happen ### Before Authorization: ``` GoogleDriveSetting Table: - is_connected = false (or null) - access_token = null - refresh_token = null - email = null ``` Error when trying to backup: "Google Drive is not connected" ### After You Click "Connect Google Drive": ``` GoogleDriveSetting Table: - is_connected = true - access_token = "ya29.a0AfH6SMB..." (long token) - refresh_token = "1//0gF..." (long token) - email = "your.email@gmail.com" ``` Backups will upload to Google Drive. ## The Error You're Getting **Error**: "Request is missing required authentication credential. Expected OAuth 2 access token..." **Means**: Either: 1. ✗ You haven't clicked "Connect Google Drive" yet, OR 2. ✗ The authorization failed silently, OR 3. ✗ The tokens expired and can't be refreshed **Solution**: Go to dashboard and click "Connect Google Drive" ## Step-by-Step to Fix ### On Your VPS: 1. **Clear any cached credentials**: ```bash php artisan cache:clear php artisan config:clear ``` 2. **Check database is ready**: ```bash php artisan migrate --force # If you get "Migration not found", the tables are already created ``` 3. **Visit your dashboard**: - Go to: `https://backup.alkashier.com` - You should see a **"Connect Google Drive"** button 4. **Click "Connect Google Drive"**: - You'll be redirected to Google's login page - Sign in with your Gmail - Grant permissions to the app - You should be redirected back with a success message 5. **Verify connection**: - Check dashboard now shows your Gmail email - Look for a "Disconnect" button instead of "Connect" 6. **Now try backing up**: - Go to **Databases** and add a test database - Go back to **Dashboard** - Click **"Backup Now"** - Check **Backup History** for results ## If Authorization Button Not Showing The "Connect Google Drive" button might not be visible if: 1. **Already connected**: Check if you see your Gmail email on the dashboard 2. **Button CSS hidden**: Inspect the page (F12 in browser) and look for a button with id containing "google" or "drive" 3. **Controller route missing**: Check routes are registered: ```bash php artisan route:list | grep google ``` Should show: ``` GET|HEAD /google-drive/authorize google-drive.authorize GoogleDriveController@authorize GET|HEAD /google-drive/callback google-drive.callback GoogleDriveController@callback POST /google-drive/disconnect google-drive.disconnect GoogleDriveController@disconnect ``` ## Check Google Cloud Console Make sure your OAuth app is set up correctly: 1. Go to [Google Cloud Console](https://console.cloud.google.com) 2. Select your project 3. Click **APIs & Services** > **Credentials** 4. Find your OAuth 2.0 Client ID 5. Click the pencil icon to edit 6. Check **Authorized redirect URIs** includes: ``` https://backup.alkashier.com/google-drive/callback ``` If you need to add it: 1. Click **+ Add URI** 2. Enter: `https://backup.alkashier.com/google-drive/callback` 3. Click **Save** 4. Wait 1-2 minutes for changes to propagate ## Check Application Logs After trying to authorize or backup, check the logs: ```bash # On VPS: tail -100 /path/to/alkashier_backup/storage/logs/laravel.log # Look for: # - "Successfully connected to Google Drive" (success) # - "Failed to connect to Google Drive:" (error) # - "Google Drive upload failed" (upload error) ``` ## Test Authorization Directly To test if your credentials work: ```bash php artisan tinker >>> use App\Services\GoogleDriveService >>> $service = new GoogleDriveService() >>> $url = $service->getAuthUrl() >>> echo $url # Copy the URL and paste in browser ``` This should redirect you to Google's login page. If you get an error here, your credentials are wrong. ## Common Scenarios ### Scenario 1: Haven't Authorized Yet **Symptoms**: - Dashboard shows "Connect Google Drive" button - `GoogleDriveSetting::first()` shows `is_connected = false` - Backups fail with "Google Drive is not connected" **Fix**: Click the button and authorize ### Scenario 2: Authorized But Upload Fails **Symptoms**: - Dashboard shows "Disconnect" button - `GoogleDriveSetting::first()` shows `is_connected = true` - Backups complete but upload fails **Check**: ```bash php artisan tinker >>> $g = \App\Models\GoogleDriveSetting::first() >>> $g->access_token # Check if token exists >>> $g->token_expires_at # Check if expired ``` **Fix**: - If token expired: Click "Disconnect" then "Connect Google Drive" again - If token invalid: Check Google Cloud Console credentials ### Scenario 3: Wrong Redirect URI **Symptoms**: - Click "Connect Google Drive" - Get redirected to Google login - After granting permission, get error like "Redirect URI mismatch" **Fix**: 1. Go to Google Cloud Console 2. Edit OAuth credential 3. Add `https://backup.alkashier.com/google-drive/callback` to authorized URIs 4. Try again ## Still Not Working? 1. Check the logs: `tail -100 storage/logs/laravel.log` 2. Check Google Cloud Console has correct URIs 3. Check `.env` has correct credentials (no spaces, exact values) 4. Try authorizing with a different Gmail account 5. Clear cache: `php artisan cache:clear` 6. Restart web server: `sudo systemctl restart apache2` (or nginx) --- **Need more help?** Review [GOOGLE_DRIVE_SETUP.md](GOOGLE_DRIVE_SETUP.md) for full setup instructions. Save