190 lines
6.8 KiB
Markdown
190 lines
6.8 KiB
Markdown
# YouTube API Scopes - Complete Reference
|
|
|
|
This document provides a comprehensive list of all YouTube API scopes available for OAuth 2.0 authentication.
|
|
|
|
## Table of Contents
|
|
|
|
1. [YouTube Data API v3 Scopes](#youtube-data-api-v3-scopes)
|
|
2. [YouTube Analytics API Scopes](#youtube-analytics-api-scopes)
|
|
3. [YouTube Reporting API Scopes](#youtube-reporting-api-scopes)
|
|
4. [YouTube Live Streaming API Scopes](#youtube-live-streaming-api-scopes)
|
|
5. [Scope Usage Guidelines](#scope-usage-guidelines)
|
|
6. [Best Practices](#best-practices)
|
|
|
|
## YouTube Data API v3 Scopes
|
|
|
|
### Basic Scopes
|
|
|
|
| Scope | Description | Access Level |
|
|
|-------|-------------|--------------|
|
|
| `https://www.googleapis.com/auth/youtube` | Manage your YouTube account | Full access |
|
|
| `https://www.googleapis.com/auth/youtube.readonly` | View your YouTube account | Read-only |
|
|
| `https://www.googleapis.com/auth/youtube.upload` | Upload YouTube videos | Upload only |
|
|
|
|
### Channel-Specific Scopes
|
|
|
|
| Scope | Description | Access Level |
|
|
|-------|-------------|--------------|
|
|
| `https://www.googleapis.com/auth/youtube.channel-memberships.creator` | Manage YouTube channel memberships | Creator access |
|
|
|
|
### Force SSL Scopes
|
|
|
|
| Scope | Description | Access Level |
|
|
|-------|-------------|--------------|
|
|
| `https://www.googleapis.com/auth/youtubepartner` | View and manage your assets and associated content on YouTube | Partner access |
|
|
| `https://www.googleapis.com/auth/youtubepartner-channel-audit` | View private information of your YouTube content | Audit access |
|
|
|
|
## YouTube Analytics API Scopes
|
|
|
|
| Scope | Description | Access Level |
|
|
|-------|-------------|--------------|
|
|
| `https://www.googleapis.com/auth/yt-analytics.readonly` | View YouTube Analytics reports for your YouTube content | Read-only |
|
|
| `https://www.googleapis.com/auth/yt-analytics-monetary.readonly` | View monetary reports for your YouTube content | Financial read-only |
|
|
|
|
## YouTube Reporting API Scopes
|
|
|
|
| Scope | Description | Access Level |
|
|
|-------|-------------|--------------|
|
|
| `https://www.googleapis.com/auth/youtube.readonly` | View YouTube reporting data | Read-only |
|
|
| `https://www.googleapis.com/auth/yt-analytics.readonly` | View YouTube Analytics reports | Read-only |
|
|
|
|
## YouTube Live Streaming API Scopes
|
|
|
|
| Scope | Description | Access Level |
|
|
|-------|-------------|--------------|
|
|
| `https://www.googleapis.com/auth/youtube` | Manage YouTube live streams | Full access |
|
|
| `https://www.googleapis.com/auth/youtube.readonly` | View YouTube live stream information | Read-only |
|
|
| `https://www.googleapis.com/auth/youtube.upload` | Upload YouTube live stream content | Upload access |
|
|
|
|
## Scope Usage Guidelines
|
|
|
|
### Choosing the Right Scope
|
|
|
|
1. **Principle of Least Privilege**: Always request the minimum scope required for your application
|
|
2. **User Experience**: Fewer scopes = better user adoption
|
|
3. **Security**: More restrictive scopes reduce potential security risks
|
|
|
|
### Common Scope Combinations
|
|
|
|
#### Basic Video Upload
|
|
```
|
|
https://www.googleapis.com/auth/youtube.upload
|
|
```
|
|
|
|
#### Channel Management
|
|
```
|
|
https://www.googleapis.com/auth/youtube
|
|
```
|
|
|
|
#### Analytics Dashboard
|
|
```
|
|
https://www.googleapis.com/auth/yt-analytics.readonly
|
|
https://www.googleapis.com/auth/youtube.readonly
|
|
```
|
|
|
|
#### Content Creator App
|
|
```
|
|
https://www.googleapis.com/auth/youtube
|
|
https://www.googleapis.com/auth/youtubepartner
|
|
```
|
|
|
|
## Best Practices
|
|
|
|
### Scope Request Best Practices
|
|
|
|
1. **Incremental Authorization**: Request additional scopes as needed rather than all at once
|
|
2. **Scope Explanation**: Provide clear explanations to users about why each scope is needed
|
|
3. **Error Handling**: Handle scope-related errors gracefully
|
|
4. **Token Management**: Store and refresh tokens securely
|
|
|
|
### Security Considerations
|
|
|
|
1. **Never hardcode scopes** in client-side code
|
|
2. **Use server-side authentication** for sensitive operations
|
|
3. **Regularly review** the scopes your application uses
|
|
4. **Monitor for scope changes** in API updates
|
|
|
|
### Example OAuth 2.0 Flow with Scopes
|
|
|
|
```javascript
|
|
// Node.js example using Google API Client Library
|
|
const {google} = require('googleapis');
|
|
const youtube = google.youtube('v3');
|
|
|
|
// Configure OAuth2 client
|
|
const oauth2Client = new google.auth.OAuth2(
|
|
'YOUR_CLIENT_ID',
|
|
'YOUR_CLIENT_SECRET',
|
|
'YOUR_REDIRECT_URL'
|
|
);
|
|
|
|
// Generate auth URL with specific scopes
|
|
const scopes = [
|
|
'https://www.googleapis.com/auth/youtube.upload',
|
|
'https://www.googleapis.com/auth/youtube.readonly'
|
|
];
|
|
|
|
const url = oauth2Client.generateAuthUrl({
|
|
access_type: 'offline',
|
|
scope: scopes
|
|
});
|
|
|
|
console.log('Authorize this app by visiting:', url);
|
|
```
|
|
|
|
## Complete Scope Reference
|
|
|
|
### All YouTube API Scopes
|
|
|
|
```
|
|
// Basic YouTube Data API
|
|
https://www.googleapis.com/auth/youtube
|
|
https://www.googleapis.com/auth/youtube.readonly
|
|
https://www.googleapis.com/auth/youtube.upload
|
|
|
|
// YouTube Partner Scopes
|
|
https://www.googleapis.com/auth/youtubepartner
|
|
https://www.googleapis.com/auth/youtubepartner-channel-audit
|
|
|
|
// YouTube Analytics
|
|
https://www.googleapis.com/auth/yt-analytics.readonly
|
|
https://www.googleapis.com/auth/yt-analytics-monetary.readonly
|
|
|
|
// YouTube Channel Memberships
|
|
https://www.googleapis.com/auth/youtube.channel-memberships.creator
|
|
```
|
|
|
|
## Scope Comparison Table
|
|
|
|
| Scope | Read | Write | Upload | Analytics | Partner | Memberships |
|
|
|-------|------|-------|--------|-----------|---------|-------------|
|
|
| `youtube` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
|
| `youtube.readonly` | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
| `youtube.upload` | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
|
|
| `youtubepartner` | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ |
|
|
| `yt-analytics.readonly` | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ |
|
|
| `youtube.channel-memberships.creator` | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
|
|
|
|
## Additional Resources
|
|
|
|
- [Official YouTube API Documentation](https://developers.google.com/youtube/v3)
|
|
- [Google OAuth 2.0 Documentation](https://developers.google.com/identity/protocols/oauth2)
|
|
- [YouTube API Scope Reference](https://developers.google.com/youtube/v3/guides/authentication)
|
|
- [Google API Client Libraries](https://developers.google.com/api-client-library)
|
|
|
|
## Troubleshooting
|
|
|
|
### Common Scope-Related Issues
|
|
|
|
1. **Insufficient Permissions**: Ensure you're requesting the correct scope for the operation
|
|
2. **Scope Mismatch**: Verify the token was obtained with the required scopes
|
|
3. **Expired Tokens**: Implement token refresh logic
|
|
4. **User Denied Scopes**: Handle authorization failures gracefully
|
|
|
|
### Debugging Tips
|
|
|
|
- Use the [Google OAuth 2.0 Playground](https://developers.google.com/oauthplayground/) to test scopes
|
|
- Check token information using the [Google Token Info endpoint](https://www.googleapis.com/oauth2/v3/tokeninfo)
|
|
- Review the [YouTube API Error Reference](https://developers.google.com/youtube/v3/docs/error-code-reference)
|
|
|
|
This comprehensive list covers all available YouTube API scopes with detailed explanations of their purposes and usage guidelines. |