Follow these steps to create a Google API key, which will allow you to use YouTube’s Data API to display videos on your WordPress site.
Step 1: Create a New Project
- Click on this link to go directly to the Google Cloud Console:
Create New Project - In the “New Project” screen, give your project a name (for example: “YouTube WP Feeder”) and click Create.
- You can leave the Location field as “No Organization” unless you’re part of an organization.
Wait a few seconds for the project to be created. Once it’s ready, a notification will popup – click Select Project to start working in the new project.
Step 2: Enable YouTube Data API v3
- After selecting your project, you’ll be taken to the Project Dashboard.
- From the dashboard, click on Go to API Overview (you’ll find this on the main dashboard).
On the API Overview page, look at the left-hand menu and click on Library.
Search for YouTube Data API v3:
In the API Library, use the search bar and type YouTube Data API v3.
Select it from the search results.
Enable YouTube Data API v3:
Click the Enable button to activate the API for your project.
Step 3: Create Credentials for your Google API Key
- After enabling the API, you will be redirected to the YouTube Data API v3 dashboard.
- Click on Create Credentials at the top of the page.
- Then choose API key from the drop down menu.
- Google will generate an API key for you. Copy the API key and store it in a safe place (you’ll use this API key when configuring your WordPress plugin).
- Click Close to finish.
Step 4: Restrict the API Key (Optional but Recommended)
- To avoid misuse of your API key, click on API & Services > Credentials in the left-hand menu.
- Find the API key you just created in the list, and click the three dots and choose Edit API key on the far right of the key.
- Under Key restrictions, you can specify restrictions:
- HTTP referrers (web sites): Use this option to restrict the API key to be used only on specific websites (e.g., your website).
- IP addresses: Restrict the key to specific IP addresses.
- After making your restrictions, click Save.
Step 5: Use the API Key in Your Plugin
Now that you have the API key, you can use it in your WordPress plugin. For example, when using the YouTube WP Feeder plugin, add the API key to the shortcode like this:
[youtube_feed channel_id="YOUR_CHANNEL_ID" api_key="YOUR_API_KEY" max_results="6"]
That’s it! You now have a fully functional API key that you can use with your YouTube Data API to fetch videos and display them on your WordPress site.