HomePHPRetrieve YouTube playlist videos using YouTube API
March 23, 2017
Retrieve YouTube playlist videos using YouTube API
Planning to integrate YouTube videos to your application? This post is for you. I will show how to retrieve YouTube videos from YouTube playlist using YouTube API.
In order to use YouTube API, you need to create or obtain API Key. By using this key, you can make YouTube Data API requests. I will be using PHP to fetch videos and display in the webpage.
1. Create YouTube API Key
To create YouTube API key, login to Google Developers Console using your Google Account and then create a project. This will show the list of libraries available. From the list, make sure to select YouTube Data API and enable it. Then it will show the screen similar to the following image:
Now that we have enabled the YouTube Data API v3, we need to Create credentials to use this API. Click the Create Credentials button to create credential. This will open form to add credentials. After filling the form properly, you will get the YouTube API Key to access data.
Click What credentials do I need? button to get API. It will create API and show the screen similar as the following:
Note down this API key and lets start fetching YouTube data.
2. Retrieve YouTube playlist videos
To retrieve YouTube Playlist videos, we need API key as well as YouTube Playlist ID. We can find YouTube Playlist Id simply by clicking the Playlist link in YouTube. The URL of that page contains Playlist Id. The following PHP code makes API request to fetch playlist videos from YouTube. Data fetched from YouTube is in JSON format.
Furthermore, we can use the API to upload videos, manage playlists and subscriptions, update channel settings, and much more. Google Developer page for YouTube is nice resource to further explore these features.