Get Videos from a YouTube channel using PHP and YouTube API

Recently, I was working with my tech blog’s (Techlomedia) mobile app and I thought to include the video section there. As it requires the use of API, I thought to put the same tutorial on this blog as well.

YouTube API offers various methods and allows you to get the videos, video data, upload, update and delete. In this article, I will show you how to fetch the latest video of a channel using the YouTube API.

Before the coding part, you need to have the API key to access the YouTube data. So, open Google API Console and enable the YouTube API for your developer account. Once you have enabled the API, you can create the API key from the credential section.

Advertisement

If you are still not sure how to get the API key, you can watch the video below.

Once you have the API access, you are ready to start with YouTube API.

Now we can start fetching the videos. Use the eblow code to fetch the videos of your own YouTube channel.

echo("<br /> Video Id : ".$video->id->videoId);//Video Id. you can use it to create video URL or embed URL

echo("<br /> Video Title : ".$video->snippet->title);//Title of the video

echo("<br /> Video Title : ".$video->snippet->thumbnails->medium->url);//Thumbnail. There are different sizes. Use as per your interest.

}

The above code will work fine if you know the Channel id. If you want to fetch videos from other channels. You need to first get the channel id from username. Username is publicly available in the URL of a channel. So, I don’t think you will face any problem.

Now use the below function in your code that will return the Channel ID.

UseThisTip is one of the best tech blogs that try to solve your computer and internet related
problems. You can find best how to technology articles here. We post best computer tricks and
internet tricks along with website review and mobile app reviews. We also do software reviews
and also try to give you list of best alternative software and apps so that you do not need to
buy paid software or app.

About

UseThisTip covers everything related to tech and web design. We have interesting tips and tricks of Software, apps, WordPress and More