from googleapiclient.discovery import build
import os
# Set up API key or OAuth 2.0 credentials
# Replace 'YOUR_API_KEY' with your actual API key or configure OAuth 2.0 credentials
# API key method
api_key = 'YOUR_API_KEY'
# OAuth 2.0 credentials method
# from google.oauth2.credentials import Credentials
# credentials = Credentials.from_authorized_user_file('path/to/credentials.json')
# Create a YouTube Data API client
youtube = build('youtube', 'v3', developerKey=api_key) # or credentials=credentials for OAuth 2.0
# Retrieve a list of videos from a channel
channel_id = 'CHANNEL_ID' # Replace with the target channel ID
videos = []
next_page_token = None
while True:
request = youtube.search().list(
part='snippet',
channelId=channel_id,
maxResults=50, # Adjust as needed, max 50 per request
pageToken=next_page_token
)
response = request.execute()
videos.extend(response['items'])
next_page_token = response.get('nextPageToken')
if not next_page_token:
break
# Print video titles
for video in videos:
print(video['snippet']['title'])