Get all video ID's from a YouTube playlist into a PHP array

Ian Zane

My goal is to use a playlist ID to get the video ID of each video within that playlist.

I'm having trouble figuring out YouTube's API (I'm a relatively new programmer).

Basically, I want to:

  1. Send an XML request to http://gdata.youtube.com/feeds/api/playlists/ID_OF_PLAYLIST
  2. Using the response (which is the part I don't understand how to navigate), append all the video IDs to an array.

Seems pretty straightforward. I've been grabbing the information from YouTube using simplexml_load_file($url); in case that is important.

Thanks for the help!

edwardmp

Here you go, I made an example:

<?php
$data = file_get_contents('http://gdata.youtube.com/feeds/api/playlists/PL4BC045240D2FB11B/?v=2&alt=json&feature=plcp');

if (!$data)
    throw new Exception("Data retrieval failed.");

$dataAsArray = json_decode($data);
$feed = $dataAsArray->feed->entry;

$videoID_array = array();

if(count($feed))
{
    foreach($feed as $item)
        array_push($videoID_array, $item->{'media$group'}->{'yt$videoid'}->{'$t'});
}

print_r($videoID_array);

?>

Where PL4BC045240D2FB11B of course is the Playlist ID! Example PHPFiddle

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Add video to user's "Watch Later" playlist on YouTube

Get all playlist ids from channel id - youtube api v3

Regex to extract both video id or playlist id from youtube url

Get all video informaion from playlist in YouTube API v3

Add video to user's Favorite/Like playlist on YouTube

Get video information from a list of playlist with youtube-dl

Youtube API - Get duration of videos from a playlist

php Youtube Get video id from live_stream

How to get video title and thumbnail from YouTube Playlist

How to get a video from a youtube playlist by count using java?

How do I create a playlist from multiple video IDs on youtube?

youtube API get all playlist id from a channel : python

Get all stored ID's from the array

Get youtube video id from youtube url in smarty template?

YouTube Objective-C API video url from playlist item

Retrieve array of video IDs from youtube playlist ID

Always get latest video in YouTube playlist

Youtube playlist all videos duration show in php

Retrieve video ids from playlist id - youtube api v3

YouTube API v3 get last video in playlist

Get youtube video Id from shared video Url

Latest youtube video from specific playlist

Regex > get YouTube Playlist ID?

get all playlist of an user from YouTube. working in api explorer but not in c#

I need some help in correcting my codes in php - How to get the video id from a YouTube URL

How to get the title of a playlist from the YouTube API

Youtube Data API: Get Title and Transcript for each video of a playlist

Is it possible to get a YouTube playlist's thumbnail URL based on the playlist ID?

Using the Youtube API, can I see if a video is in a playlist without retrieving the entire playlist and looping through all the videos?