Thats more a youtube than a wordpress question. But you can write a simple shortcode function and add it to your site.
// Add Shortcode
function custom_youtubeapishortcode()
{
$playlistid = "XXXX";
$apikey = "XXXX";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=".$playlistid."&maxResults=1&key=".$apikey."",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Accept: */*",
"Accept-Encoding: gzip, deflate",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Host: www.googleapis.com",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$array = json_decode($response, true);
return apply_filters('the_content', "https://youtu.be/".$array['items']['0']['snippet']['resourceId']['videoId']);
}
}
add_shortcode('youtubeapishortcode', 'custom_youtubeapishortcode');
Than you should get a api key for youtube from google developers :https://console.developers.google.com/
Add the api Key and the youtube playlist ID to the code and add it to your functions.php
Call the shortcode on any page:
[youtubeapishortcode]