How to Get YouTube Subscriber count, Video count and Total view count

Hello Friends…

Let me show you a code to access your YouTube Chanel Subscriber count, Video count and Total view count.

<?php
$api_url = 'https://content.googleapis.com/youtube/v3/channels';

$query = [
    'id' => '<YOUR_YOUTUBE_CHANNEL_ID>', // Keep your Channel ID.
    'key' => '<YOUR_API_KEY>', // Keep Your API Key here.
    'part' => 'statistics',
];

$request_url = sprintf(
    '%s?%s',
    $api_url,
    http_build_query( $query )
);

$response_json = json_decode( file_get_contents( $request_url ) );

echo "Subscriber - ".$response_json->items[0]->statistics->subscriberCount;
echo "<br>Video - ".$response_json->items[0]->statistics->videoCount;
echo "<br>View Count - ".$response_json->items[0]->statistics->viewCount;
?>

Thank You 🙂 Stick with us. We will keep posted.

Blog Catagory : Blog