Hello Internet People, did you just install a WordPress plugin for YouTube videos, but now you realized that you need a YouTube API key to properly use the plugin?
In this tutorial, I’ll show you how to generate an API key (or as some refer to it as API secret or Access Token), how to secure it and how to retrieve one if you have lost yours.
API key is really useful for Video metadata which Google uses for ranking videos and websites.
If you are looking for API key for Android, check this tutorial.
CONTENTS
How to resolve errors with YouTube API key
How to retrieve your Google YouTube API key at any time
How to protect your API key with IP or domain restriction
Does YouTube API cost anything
Why WordPress plugins need YouTube API key
How to get a YouTube API key
To get a YouTube API Key to follow below steps:
First of all, make sure you are logged in into Google, this will make this tutorial smoother.
- Go to developers.google.com and login (or create an account – it’s free).
2. At top of the page Next to Google APIs logo, click on the drop-down.
3. A popup will appear that prompts you to select a project, but we just want to create a new project.
4. So select “New Project” at the top right corner of the popup.
5. Add a project name.
6. The location is optional, this just means the location in a folder. It’s useful if you have a lot of different APIs.
7. Then click on create.
8. In the search box at the top of the console search for “youtube”.
9. There will be few options, but you should select “YouTube Data API v3”.
10. On this YouTube’s API library page, click on Enable.
11. And in the left column select “Credentials”.
12. Click on the “Create credentials” drop-down.
13. Then select “API key”.
14. Now your API key is created.
15. You can see there is a small exclamation mark here, I’ll explain this in just a few seconds.
16. But for now, just click on “copy to clipboard” button.
17. Now you can paste the API key to WordPress and your videos will have full information.
Here is an example of YouTube API key:
It’s just a string of letters and numbers.
How to resolve errors with YouTube API key
If you are having any issues or errors with the API key, the easiest way is to delete it and create a new one.
How to retrieve your Google YouTube API key at any time
To retrieve your YouTube API key:
- Go to your projects from the drop-down next to Google APIs logo at the top.
2. Select “Credentials” from the left column.
3. Here you will see all your API keys.
4. Just click on the “copy to clipboard”.
How to protect your API key with IP or domain restriction
To protect your YouTube API key do this:
So.. let’s go back to the exclamation mark. This is a way for Google to tell you that the API key is not protected. Google recommended that you add a restriction, just to increase the security.
Now please note that some plugins don’t seem to work with the IP restrictions. So double check in the plugin’s FAQs if this will work.
We are here in the project we just created.
Click on edit – it’s the little pen next to your API key.
Add a name to the restriction.
Then select how you want to restrict the key.
Most common ways are HTTP and IP address restrictions.
I’ll use an IP address. In most cases, you will need your website’s IP address.
To find your websites IP address, just go to google and search for “find my website IP”.
Click on the first result.
In the search box type in your website URL.
The website will give you, your website’s IP address.
Just copy the IP address.
And paste it in API restriction.
At the bottom of the page click on “Save”.
Does YouTube API cost anything
The API key doesn’t cost anything as long as you keep it 1 million units per day. Actions have different unit costs, you can use this calculator.
However, if you are running a small or medium sized website, you won’t exceed the quota. For more info check the guide by Google.
Why WordPress plugins need YouTube API key
WordPress plugins need to be able to access more information about the video. This is especially useful for metadata and other data about the video.
In most cases, you don’t need to use API, because you can just embed a video or playlist directly from YouTube. But for example for gallery feature, you will need the key.