The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Make a YouTube comment archiver

Creating a YouTube comment archiver means building a tool or script that fetches comments from a YouTube video and stores them (archives) for later use or analysis. Here’s a simple way to do this using Python and the YouTube Data API.


How It Works:

  • Use the YouTube Data API v3 to fetch comments from a video.

  • Save comments in a file (e.g., JSON or CSV) for archiving.


Prerequisites:

  1. Python installed on your system.

  2. Google Cloud Console project with YouTube Data API enabled.

  3. API Key from Google Cloud Console.


Step-by-Step Python Script

python
import os import json import requests API_KEY = 'YOUR_YOUTUBE_API_KEY' VIDEO_ID = 'YOUR_VIDEO_ID' COMMENTS_PER_PAGE = 100 # max allowed by YouTube API def get_comments(video_id, api_key): comments = [] base_url = "https://www.googleapis.com/youtube/v3/commentThreads" params = { 'part': 'snippet', 'videoId': video_id, 'maxResults': COMMENTS_PER_PAGE, 'textFormat': 'plainText', 'key': api_key } while True: response = requests.get(base_url, params=params) if response.status_code != 200: print(f"Error: {response.status_code} - {response.text}") break data = response.json() for item in data.get('items', []): comment = item['snippet']['topLevelComment']['snippet'] comments.append({ 'author': comment['authorDisplayName'], 'comment': comment['textDisplay'], 'published_at': comment['publishedAt'], 'like_count': comment['likeCount'] }) # Pagination check if 'nextPageToken' in data: params['pageToken'] = data['nextPageToken'] else: break return comments def save_comments_to_json(comments, filename): with open(filename, 'w', encoding='utf-8') as f: json.dump(comments, f, ensure_ascii=False, indent=4) if __name__ == "__main__": video_id = VIDEO_ID api_key = API_KEY comments = get_comments(video_id, api_key) print(f"Fetched {len(comments)} comments.") save_comments_to_json(comments, f'{video_id}_comments.json') print(f"Comments saved to {video_id}_comments.json")

How to Use

  • Replace 'YOUR_YOUTUBE_API_KEY' with your actual API key.

  • Replace 'YOUR_VIDEO_ID' with the YouTube video ID you want to archive comments from.

  • Run the script; it will fetch all comments and save them in a JSON file named {video_id}_comments.json.


Notes

  • YouTube API quota limits apply — extensive fetching might require quota management.

  • This script archives only top-level comments; replies can be added with an extension.

  • You can modify output to CSV if needed for easier reading or Excel import.

If you want me to build a version that includes replies or exports to CSV, just ask!

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About