Overview
Popcorn Vision uses The Movie Database (TMDB) API to fetch movie and TV show information. You’ll need to create a free TMDB account and generate API credentials before running the application.TMDB API is completely free for non-commercial use. Commercial usage requires approval from TMDB.
Prerequisites
- A valid email address
- Agreement to TMDB’s Terms of Service and API Terms of Use
- A brief description of how you’ll use the API (e.g., “Personal movie tracking application”)
Getting Your API Credentials
Create a TMDB Account
Navigate to The Movie Database and click Sign Up in the top right corner.Fill in your details:
- Username
- Password
- Email address
Navigate to API Settings
Once logged in:
- Click your profile icon in the top right
- Select Settings from the dropdown
- Click API in the left sidebar
Request an API Key
On the API page, you’ll see a section to request an API key.
- Click click here link under “Request an API Key”
- Choose Developer (for non-commercial use)
- Accept the Terms of Use
Fill Out the Application Form
Provide the required information:Application Name: Popcorn Vision (or your custom name)Application URL: Your deployment URL or Click Submit when complete.
http://localhost:3000 for developmentApplication Summary: A brief description, such as:Copy Your API Credentials
You’ll immediately see your API credentials. Copy both:
Your main API key - a 32-character hexadecimal string.Example format:
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6Copy this value to API_KEY in your .env.local file.A longer JWT token used for some v4 API endpoints.Example format:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... (much longer)Copy this value to API_READ in your .env.local file.Configuring Popcorn Vision
After obtaining your credentials, add them to your environment configuration:Understanding API Versions
TMDB offers two API versions, and Popcorn Vision uses both:API v3 (API Key)
The traditional REST API using an API key for authentication.Used for:
- Fetching movie/TV data
- Search functionality
- Discover endpoints
- Most read operations
api_key=YOUR_KEYAPI v4 (Bearer Token)
Newer API version using OAuth-style bearer token authentication.Used for:
- User account operations
- Lists management
- Ratings and favorites
- Write operations
Authorization: Bearer YOUR_TOKENPopcorn Vision primarily uses v3 API endpoints. The v4 Read Access Token is included for future compatibility and advanced features.
API Usage in Popcorn Vision
Here’s how your API credentials are used throughout the application:Server-Side API Client
The main API client is configured insrc/lib/axios.js:
- Adds your API key to all requests
- Caches responses for 1 hour to reduce API calls
- Uses Next.js fetch adapter for optimal performance
API Routes
Popcorn Vision uses Next.js API routes to proxy TMDB requests:/api/search/query- Search for movies/TV shows/api/search/filter- Filter and discover content/api/authentication/*- User authentication flows/api/account/*- User account management/api/[[...segments]]- Catch-all proxy for other TMDB endpoints
API keys are kept secure on the server. They’re never exposed to client-side JavaScript.
Rate Limits
TMDB enforces rate limits to ensure fair usage:40 requests per 10 seconds per IP addressIf you exceed this limit, you’ll receive a
429 Too Many Requests response.Avoiding Rate Limits
Popcorn Vision includes several strategies to stay within limits:- Response Caching: API responses are cached for 1 hour using Next.js cache
- Request Batching: Multiple data points are fetched in single requests using
append_to_response - Rate Limiting Middleware: Built-in rate limiting using the
limiterpackage
Testing Your API Connection
Verify your TMDB API credentials are working correctly:Check the Application
Open http://localhost:3000 in your browser.If configured correctly, you should see:
- Movie posters and backdrops loading
- Trending movies on the homepage
- Search functionality working
Test an API Endpoint Directly
You can test your API key directly using curl:A successful response will return JSON with popular movies:
Troubleshooting
401 Unauthorized Error
401 Unauthorized Error
429 Rate Limit Error
429 Rate Limit Error
Problem: Too Many Requests error from TMDB.Cause: You’ve exceeded 40 requests per 10 seconds.Solutions:
- Implement caching for API responses
- Reduce the number of API calls on page load
- Wait 10 seconds and try again
- Check for infinite loops in your code making repeated API calls
Images Not Loading
Images Not Loading
Problem: Movie posters and backdrops are broken.Cause: Image CDN URLs not configured.Solution:
Ensure all
NEXT_PUBLIC_API_IMAGE_* variables are set in .env.local. Copy them from .env.example:API Key Revoked or Suspended
API Key Revoked or Suspended
Problem: Your API key stops working.Causes:
- Violation of TMDB Terms of Service
- Commercial use without approval
- Excessive API usage
- Check your email for notices from TMDB
- Review TMDB API Terms
- Contact TMDB support if you believe it’s an error
- Request a new API key if necessary
Network or CORS Errors
Network or CORS Errors
Problem: CORS errors in browser console.Cause: Direct API calls from client-side code.Solution:
Always use Popcorn Vision’s API routes (e.g.,
/api/search/query) instead of calling TMDB directly from the browser. The Next.js API routes act as a secure proxy.API Documentation
For advanced usage and custom integrations, refer to the official TMDB API documentation:TMDB API v3 Docs
Complete API v3 reference with all endpoints and parameters
TMDB API v4 Docs
API v4 documentation for advanced authentication and features
API Support
TMDB community forums for API support and questions
Rate Limits Guide
Detailed information about TMDB rate limiting policies
Next Steps
Environment Variables
Configure all environment variables for Popcorn Vision
Deployment
Deploy your configured instance to production