YouTube APIs are the most popular APIs and daily hundreds of users from around the world search for it on the internet. In this article I am describing the simplest procedure to use YouTube Data API.
Use the YouTube API with PHP
First thing you need is to create an account on Google or if you have Gmail account, that is enough. To use any Google API, one first needs to go to Google Developer Console and create a project there.
Please click on the link: https://console.developers.google.com/
On dashboard page, you will see a list of all APIs provided by Google, including the 3 APIs for using YouTube functionality.
To use YouTube Data API, click YouTube Data API link.
On next page click Create project to create a project first.
Now after the creation of project, click Enable button to enable the API for usage.
Select Browse key 1, click Create API key to get your API key. Copy and save it for later use inside the code.
Here is an example code to get the list of popular videos on YouTube.
$api_key = '****insert your API KEY here******';
$ch = curl_init("https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&key=".$api_key);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec($ch);
$response = json_decode($result);
For Complete API documentation, Please Follow:
Just read the API documentation and with some changes in the above code, you can easily get much more information about YouTube videos.