Overview
Access information about movies, TV shows, actors, and more
Integration Guide
Step 1: Get API Key
To use The Movie Database API, you need to sign up for an account and request an API key.
- Visit TMDB Sign Up to create an account
- Verify your email address
- Go to your API Settings page
- Request an API key for developer use
- Fill out the required information about your application
- Once approved, you'll receive your API key
Step 2: Set Up Your Project
Create the necessary files for your movie explorer application:
- index.html - The HTML structure
- styles.css - CSS for styling
- movies.js - JavaScript for API integration
- placeholder.jpg - A fallback image for movies without posters
- placeholder-person.jpg - A fallback image for actors without profile pictures
Step 3: Implement the Code
Copy the following code into your project files:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Movie Explorer</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<header>
<h1>Movie Explorer</h1>
<div class="search-container">
<input type="text" id="search-input" placeholder="Search for movies...">
<button id="search-btn">Search</button>
</div>
</header>
<nav class="tabs">
<button class="tab-btn active" data-tab="popular">Popular</button>
<button class="tab-btn" data-tab="trending">Trending</button>
<button class="tab-btn" data-tab="search-results">Search Results</button>
</nav>
<main>
<div id="movies-grid" class="movies-grid">
<!-- Movies will be displayed here -->
<div class="loading">Loading movies...</div>
</div>
<div class="pagination" id="pagination">
<!-- Pagination controls will be displayed here -->
</div>
</main>
<!-- Movie Details Modal -->
<div id="movie-modal" class="modal">
<div class="modal-content">
<span class="close-btn">×</span>
<div id="movie-details" class="movie-details">
<!-- Movie details will be displayed here -->
</div>
</div>
</div>
</div>
<script src="movies.js"></script>
</body>
</html>Step 4: Replace the API Key
Replace your_api_key_here in the JavaScript file with your actual API key.
Security Note
Step 5: Test Your Implementation
Open your HTML file in a browser to test your movie explorer application. You should be able to:
- Browse popular and trending movies
- Search for movies by title
- View detailed information about a movie by clicking on it
- Watch movie trailers
- See the cast of each movie
- Navigate through paginated results
Error Handling
Common Errors
- 401 Unauthorized: Invalid API key
- 404 Not Found: The resource you requested could not be found
- 429 Too Many Requests: Rate limit exceeded
Rate Limiting
The Movie Database API has rate limits to prevent abuse:
- 40 requests every 10 seconds
- Approximately 3 requests per second
Best Practice
Image Handling
The Movie Database API provides different image sizes for posters and backdrops. The base URL for images is https://image.tmdb.org/t/p/followed by the size and file path.
Common poster sizes:
- w92 - Small
- w185 - Medium
- w500 - Large
- original - Original size
Always implement fallback images for cases where movie posters or actor profiles are not available.
API Details
- Base URL
https://api.themoviedb.org/3- Authentication
- API Key
- Documentation
- Official Docs
Endpoints
- GET
/movie/popularGet a list of popular movies
Parameters
api_key*string - Your API keylanguagestring - ISO 639-1 language code (default: en-US)pagenumber - Page number (default: 1)regionstring - ISO 3166-1 region code
- GET
/movie/{movie_id}Get detailed information about a specific movie
Parameters
movie_id*number - The ID of the movieapi_key*string - Your API keylanguagestring - ISO 639-1 language code (default: en-US)append_to_responsestring - Additional data to include (e.g., videos,images,credits)
- GET
/search/movieSearch for movies by title
Parameters
api_key*string - Your API keyquery*string - Text query to searchlanguagestring - ISO 639-1 language code (default: en-US)pagenumber - Page number (default: 1)include_adultboolean - Include adult content (default: false)regionstring - ISO 3166-1 region codeyearnumber - Year of releaseprimary_release_yearnumber - Primary year of release
- GET
/trending/{media_type}/{time_window}Get trending movies, TV shows, or people
Parameters
media_type*string - Type of media (all, movie, tv, person)time_window*string - Time window (day, week)api_key*string - Your API key
- GET
/movie/{movie_id}/creditsGet the cast and crew for a movie
Parameters
movie_id*number - The ID of the movieapi_key*string - Your API keylanguagestring - ISO 639-1 language code (default: en-US)