mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-12 11:26:29 +00:00
Add YouTube example to list videos in a playlist
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
require '../src/Curl/Curl.php';
|
||||
|
||||
use \Curl\Curl;
|
||||
|
||||
|
||||
define('YOUTUBE_API_KEY', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
|
||||
|
||||
$playlistId = 'RDHJb0VYVtaNc';
|
||||
|
||||
$curl = new Curl();
|
||||
$curl->get('https://www.googleapis.com/youtube/v3/playlistItems', array(
|
||||
'key' => YOUTUBE_API_KEY,
|
||||
'maxResults' => '50',
|
||||
'part' => 'snippet',
|
||||
'playlistId' => $playlistId,
|
||||
));
|
||||
|
||||
echo 'Songs in this playlist:' . "\n";
|
||||
|
||||
foreach ($curl->response->items as $item) {
|
||||
echo
|
||||
$item->snippet->title . "\n" .
|
||||
'https://www.youtube.com/watch?v=' . $item->snippet->resourceId->videoId . "\n" .
|
||||
"\n";
|
||||
}
|
||||
Reference in New Issue
Block a user