In this tutorial I will show you how to get YouTube subscribers count in php using api v3.0. We need just an API KEY to get work. Below I am sharing all the steps to get api key and get subscribers count.
How to get YouTube API key
Below are the steps to get YouTube API key
1. Go to https://console.developers.google.com/ and login to your google account.
2. Navigate to “Library”.
3. Now click on “YouTube Data API” link under “YouTube APIs” and click on “Enable” Button.
4. Now your YouTube API has been enabled for your project. Now click on “Create credentials” button or “credentials” in left menu.
6. Now select “Public data” for access and click on “What credentials do I need?” button.
7. Here you will get your credentials and click “done”.
How to get YouTube subscribers count in php
To get remote content in php, we have curl and file_get_contents() methods. Below we are calling YouTube api to get subscribers count. Please change YOUR_CHANNEL_ID and YOUR_API_KEY with yours.
// Calling api. $subscribers = file_get_contents('https://www.googleapis.com/youtube/v3/channels?part=statistics&id=YOUR_CHANNEL_ID&key=YOUR_API_KEY'); // Decoding json response $response = json_decode($subscribers, true ); // echoing subscribers count. echo $count = intval($response['items']['statistics']['subscriberCount']);
So now you can easily get your YouTube subscribers count in php using api v3.0.