# Onairos Flutter Package - Consuming App Setup Guide

## 🚨 **CRITICAL: Required Setup for YouTube/Google Integration**

**Why is YouTube crashing?** The YouTube/Google Sign-In integration requires each consuming app to configure their own Google credentials. The package cannot use hardcoded credentials for security and functionality reasons.

## 📋 **Required Setup Steps**

### **Step 1: Google Cloud Console Setup**

1. **Create Google Cloud Project**
   - Go to [Google Cloud Console](https://console.cloud.google.com/)
   - Create a new project or select existing one
   - Note your project ID

2. **Enable APIs**
   - Go to "APIs & Services" → "Library"
   - Enable these APIs:
     - **YouTube Data API v3** (for YouTube integration)
     - **Google Sign-In API**
     - **Gmail API** (if using Gmail integration)

3. **Create OAuth 2.0 Credentials**
   - Go to "APIs & Services" → "Credentials"
   - Click "Create Credentials" → "OAuth 2.0 Client IDs"
   - Create separate credentials for:
     - **iOS**: Bundle ID must match your iOS app
     - **Android**: Package name and SHA-1 certificate fingerprint
     - **Web**: For backend integration

### **Step 2: iOS Configuration**

1. **Download GoogleService-Info.plist**
   - Download from Firebase Console or Google Cloud Console
   - Place in `ios/Runner/` directory
   - Add to Xcode project

2. **Update Info.plist**
   ```xml
   <key>CFBundleURLTypes</key>
   <array>
     <dict>
       <key>CFBundleURLName</key>
       <string>REVERSED_CLIENT_ID</string>
       <key>CFBundleURLSchemes</key>
       <array>
         <string>YOUR_REVERSED_CLIENT_ID</string>
       </array>
     </dict>
   </array>
   ```

### **Step 3: Android Configuration**

1. **Download google-services.json**
   - Download from Firebase Console or Google Cloud Console
   - Place in `android/app/` directory

2. **Update build.gradle**
   ```gradle
   // android/build.gradle (project level)
   dependencies {
     classpath 'com.google.gms:google-services:4.3.15'
   }

   // android/app/build.gradle
   apply plugin: 'com.google.gms.google-services'
   ```

3. **Get SHA-1 Certificate**
   ```bash
   # Debug certificate
   keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

   # Release certificate
   keytool -list -v -keystore YOUR_RELEASE_KEYSTORE -alias YOUR_ALIAS
   ```

### **Step 4: Update Onairos Configuration**

**Option A: Environment Variables (Recommended)**
```dart
// Set these in your app before using Onairos
const String GOOGLE_CLIENT_ID = String.fromEnvironment('GOOGLE_CLIENT_ID');
const String GOOGLE_CLIENT_SECRET = String.fromEnvironment('GOOGLE_CLIENT_SECRET');

// Initialize Onairos with your credentials
Onairos(
  AppName: 'Your App Name',
  googleClientId: GOOGLE_CLIENT_ID, // Your client ID
  onResolved: (apiUrl, token, userData) {
    // Handle success
  },
)
```

**Option B: Direct Configuration**
```dart
Onairos(
  AppName: 'Your App Name',
  googleClientId: 'YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com',
  onResolved: (apiUrl, token, userData) {
    // Handle success
  },
)
```

## 🔧 **Current API Endpoints**

### **Production APIs (Live)**
- **Base URL**: `https://api2.onairos.uk`
- **YouTube**: `https://api2.onairos.uk/youtube/authorize`
- **Reddit**: `https://api2.onairos.uk/reddit/authorize`
- **Pinterest**: `https://api2.onairos.uk/pinterest/authorize`
- **LinkedIn**: `https://api2.onairos.uk/linkedin/authorize`
- **Instagram**: Uses Opacity SDK (production)

### **Configuration Required**
Each platform needs proper client IDs configured:

```dart
// Example configuration
const OAUTH_CONFIG = {
  'youtube': {
    'clientId': 'YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com',
    'hasNativeSDK': true,
  },
  'instagram': {
    'clientId': 'YOUR_INSTAGRAM_CLIENT_ID',
    'hasNativeSDK': true, // Uses Opacity SDK
  },
  'reddit': {
    'clientId': 'YOUR_REDDIT_CLIENT_ID',
    'hasNativeSDK': false,
  },
  'pinterest': {
    'clientId': 'YOUR_PINTEREST_CLIENT_ID',
    'hasNativeSDK': false,
  },
};
```

## 🛠️ **Platform-Specific Setup**

### **YouTube Integration**
- Requires Google OAuth 2.0 setup (above)
- Uses native Google Sign-In SDK
- Needs YouTube Data API v3 enabled
- Scopes: `youtube.readonly`

### **Instagram Integration**
- Uses Opacity SDK (native)
- Requires Instagram Basic Display API setup
- Get client ID from Facebook Developers Console

### **Reddit Integration**
- Uses web OAuth flow
- Register app at https://www.reddit.com/prefs/apps
- Get client ID and secret

### **Pinterest Integration**
- Uses web OAuth flow
- Register app at https://developers.pinterest.com/
- Get client ID and secret

## ⚠️ **Common Issues & Solutions**

### **"Google Sign-In Failed"**
- Check bundle ID matches OAuth credentials
- Verify GoogleService-Info.plist is properly added
- Ensure SHA-1 certificate is registered for Android

### **"Client ID Not Found"**
- Verify you're using your own client ID, not the demo one
- Check the client ID format is correct

### **"YouTube Data API Disabled"**
- Enable YouTube Data API v3 in Google Cloud Console
- Check API quotas and billing

## 📝 **Testing Checklist**

- [ ] Google Cloud project created
- [ ] YouTube Data API v3 enabled
- [ ] OAuth credentials created for iOS/Android
- [ ] GoogleService-Info.plist added to iOS
- [ ] google-services.json added to Android
- [ ] Bundle ID/Package name matches credentials
- [ ] SHA-1 certificate registered (Android)
- [ ] Client IDs updated in app configuration
- [ ] Test YouTube sign-in flow
- [ ] Test other platform connections

## 🆘 **Need Help?**

1. **Check Google Cloud Console logs** for detailed error messages
2. **Verify API quotas** aren't exceeded
3. **Test with simple Google Sign-In** first before YouTube integration
4. **Check bundle ID/package name** matches exactly
5. **Ensure certificates** are properly registered

**Remember**: Each consuming app must have its own Google Cloud project and credentials. The hardcoded credentials in the package are for demonstration only and will not work in production. 