DEV Community

Ichi
Ichi

Posted on • Edited on

5 3

[PHP] Get information about a specific YouTube video

If you want to get the video information of a specific channel or the playlist list, I think you will use YouTube API v3.
With PHP, it's good to use the official Google library with Composer, but for specific videos you can get the video information more easily.

Specifically, the JSON that stores the video information is called from the API.
that's all!

JSON URL Structure

https://www.googleapis.com/youtube/v3/videos?id=[VideoID]&key=[APIKey]&part=snippet,contentDetails,statistics,status

Enter the API key obtained from Google API in [API Key].
There are many ways to get the key on the internet, so please check it yourself.

Sample Code

Try to get the title of a specific video from YouTube API v3.

$api_key = "API Key"
$video_id = "Video ID"
$url = "https://www.googleapis.com/youtube/v3/videos?id=$video_id&key=$api_key&part=snippet,contentDetails,statistics,status";
$json = file_get_contents($url);
$getData = json_decode( $json , true);
foreach((array)$getData['items'] as $key => $gDat){
    $title = $gDat['snippet']['title'];
}
// Output Title
echo $title;
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (2)

Collapse
 
aheisleycook profile image
privatecloudev

good post I use php and larevel also a wordpress admin/

Collapse
 
ichii731 profile image
Ichi

I am happy to help you.
Please take a look at Twitter if you like.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay