Extracting Title Description Thumbnail using Youtube Data API

YouTube Data API library can be used to implement API based access to YouTube videos. Using this library we can extract video data like title, description, video thumbnail, create playlists, channels and more. You can refer more code samples available with the YouTube Data API library. For accessing this library from our PHP application we have to create YouTube Data API project and get the API key. We have to pass this key from our PHP web application along with the API request for accessing the required YouTube service.

I used Youtube Data API v3 library to extract data from the video URL. In a previous PHP tutorial, I have presented you a PHP script to create image thumbnail of a YouTube video without using Youtube Data API. The image thumbnail source is formed by using the video id. In this PHP script example, I am sending the video id with the API key while requesting YouTube Data API access. I parsed the resultant API response to get the video data like title and description. Thumbnail along with the title and description will tell more about the video at the first sight. In SEO point of view text content gives more advantages than the media contents like images, videos. So, showing videos with informative text data will help your video gallery page to be ranked higher.

How to Get YouTube Video Data API Key

In this section, I have listed the steps required to get the YouTube data API key.

Step3: Generate API key by selecting the newly created project. A popup will show the API key credential as shown below. This API key will be sent while requesting YouTube data.

HTML Form to Get Video URL

The following code shows the HTML form to request YouTube video URL for the given input. When the URL submitted via this form, the video id will be extracted from the URL. This id will be passed with the API key to get the YouTube data. After getting YouTube data, the video thumbnail, title and the description will be displayed below the HTML form. For displaying video thumbnail, the YouTube video embed URL is formed by using the unique video id. The code shows the iframe with the source of the video embed.

Request Google API to Get YouTube Data via the V3 library using PHP

The following CURL request is sent to the Google API to get YouTube video data by using YouTube Data API V3 library. In the API request, we have to send the API key and the unique id of the video. The id will be extracted from the video URL posted via the form. After getting YouTube data, I have parsed the response to get the title and the description.