Set Up the Credentials
Set up your credentials to get the API key for The Movie Database.
We'll cover the following
To use The Movie Database (TMDB) API platform, we need to create an account on TMDB.
Create an account
We can sign up for our TMDB account on their official page. Please follow the steps below to successfully sign up:
-
Fill in the primary details like username, password, and email address and click “Sign Up”.
-
Before you can log in to your account, you need to verify your email address to activate it. Go to your inbox and click the verification link in the verification email sent by TMDB.
-
Enter your username and password to log in.
-
A successful login would take you to the homepage of TMDB.
The slides below are to help you visualize the process.
Get the API key
Please follow the steps below to register for an API key:
- Log in to your TMDB account.
- Click on your name icon at the top right corner and then click “Settings” to go to the settings page.
- Click “API” to go to the API creation page.
- Click “click here” under the “Request an API Key” section.
- Select “Developer” as the type of your API.
- Click “Accept” to agree with the terms of use of TMDB API.
- Fill in the application details and click “Submit”.
Note: The “Application URL” field takes in any random URL as our application URL. For example, www.example.com.
- TMDB API key generated successfully!
The slides below are to help you visualize the process.
Check your API key
Since we have our TMDB API key with us, get ready to do some great stuff! Here’s a sneak peek of how we can use our API key to fetch the required information. Let’s run the code below to fetch the popular movies on TMDB.
If you haven’t already entered your API_KEY
then please click “Edit” and enter the value. Now, click “Run” to execute the code.
import fetch from "node-fetch";const API_KEY = '{{API_KEY}}';const endpointUrl = new URL('https://api.themoviedb.org/3/movie/popular');const queryParameters = new URLSearchParams({api_key: API_KEY,language: 'en-US'});async function fetchData() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl);// Call to function that prints the responseprintResponse(response);} catch (error) {// Call to function that prints the error message, if anyprintError(error);}}// Call to function that makes API callfetchData();
If your API key is valid, it will lead to a successful call of TMDB’s popular movies endpoint, and we’ll get a list of popular movies with their details as our output. We’ll explore all such endpoints together throughout this course, so let’s get started.