youtube subscribers count in wordpress using api

How to get youtube subscribers count in wordpress using api

Today i’m operating with youtube api to induce youtube subscribers count in wordpress. Then i found The YouTube API v2.0 is deprecated. And 3.0 has been discharged therefore no have to be compelled to oauth with this api version.

We have to simply require an API KEY to get work. Let’s see a way to get youtube subscribers count in php and wordpress api v3.0. following i’m shring all the steps to induce api key and find subscribers count.

How to get youtube api key:-
following area unit the steps to induce youtube api key
1. move to https://console.developers.google.com/. And log in to your google account.

2. Navigate to APIs & auth and click on on APIs.

3. currently click on YouTube information API link underneath YouTube APIs. and click on on Enable API Button.

4. currently your youtube api has been enabled for your project. currently click on credentials underneath APIs & auth.

php - How to get youtube subscribers count using php
How to get youtube subscribers count using wordpress

5. Click on Add Credentials Then API key in dropdown.

php - How to get youtube subscribers count using php
How to get youtube subscribers count using wordpress

6. currently a brand new popup window can seem, click on Browser key button. Then fill your URL if any else click on Create Key button.

php - How to get youtube subscribers count using php
How to get youtube subscribers count using wordpress

7. a brand new popup window can seem that showing your API key. Copy and use this key to induce subscribers count.

How to get youtube subscribers count in wordpress

There area unit wpxs_remote_get() methodology in wordpress to urge remote contents. following we tend to area unit business youtube api to urge subscribers count. amendment YOUR_CHANNEL_ID and YOUR_API_KEY with yours.

$subscribers_params = array('sslverify' => false,'timeout' => 60);

$youtube_subscribers = wpxs_remote_get('https://www.googleapis.com/youtube/v3/channels?part=statistics&id=YOUR_CHANNEL_ID&key=YOUR_API_KEY', $subscribers_params);
if (is_wpxs_error($youtube_subscribers) || '400' <= $youtube_subscribers['response']['code'] ) 
{
	// error in replay 
    echo 'Something went wrong';
} 
else 
{
	//  json decode of youtube api response
    $youtube_api_response = json_decode( $youtube_subscribers['body'], true );
	
	// get youtube subscribers count.
    $subscribers_count = intval($youtube_api_response['items'][0]['statistics']['subscriberCount']);
	
	// print youtube subscribers count.
    echo $subscribers_count;
}

So currently you’ll be able to simply get your youtube subscribers count in php and wordpress victimisation api v3.0.

Leave a Comment

Your email address will not be published. Required fields are marked *

8  +  2  =  

We accept paid advance and paid guest Posting on our Site : Contact US