Skip to content

Instantly share code, notes, and snippets.

@vallieres
Created May 18, 2017 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vallieres/43f05dba05ad8b0bca4753b7d8064462 to your computer and use it in GitHub Desktop.
Save vallieres/43f05dba05ad8b0bca4753b7d8064462 to your computer and use it in GitHub Desktop.
List YouTube's Channel Videos Not in a Playlist
<?php
function getSslPage($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
//params
$order = "date";
$part = "snippet";
$channel_id = "UCtinbF-Q-fVthA0qrFQTgXQ";
$max_results = 50;
$api_key = "APIKEYGOESHERE";
$feedurl = 'https://www.googleapis.com/youtube/v3/search?order='.$order.'&part='.$part.'&channelId='.$channel_id.'&maxResults='.$max_results.'&key='.$api_key;
print($feedurl . PHP_EOL. PHP_EOL);
$feed = getSslPage($feedurl);
$feed_arr = json_decode($feed, true);
//print_r($feed_arr);
$items = $feed_arr['items'];
foreach($items as $item) {
if( (isset($item['id']['videoId'])) OR (!empty($item['id']['videoId'])) ) {
echo 'https://www.youtube.com/watch?v='.$item['id']['videoId'] . PHP_EOL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment