1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| <?php
$channelId = 'id de la chaîne...';
$apiKey = 'Api Key....';
$activitiesUrl = "https://www.googleapis.com/youtube/v3/activities?part=snippet,contentDetails,id&channelId=$channelId&maxResults=5&key=$apiKey&format=json";
$curl = curl_init($activitiesUrl);
/*Seulement sur localhost :
Désactiver la vérification du host et le certificat
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
*/
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response=curl_exec($curl);
if($response === false)
{
echo 'Curl error: ' . curl_error($curl);
}
else
{
echo 'Operation completed without any errors'."\n\r";
$activitiesData =json_decode($response);
$html="";
if (isset($activitiesData->items) && count($activitiesData->items) > 0) {
foreach($activitiesData->items as $index=>$item){
$videoId = $item->contentDetails->upload->videoId;
$videoTitle = $item->snippet->title;
$videoDescription = $item->snippet->description;
$videoThumbnail = $item->snippet->thumbnails->default->url;
// Générer le code HTML pour afficher la vidéo
$html .= '<div class="video-responsive">';
$html .= '<iframe width="560" height="315" src="https://www.youtube.com/embed/' . $videoId . '" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>';
$html .= '</div>';
}
// Afficher le code HTML
echo $html;
}
}
curl_close($curl); |