Custom Index Module
Posted: Fri Aug 16, 2024 10:35 am
Morning all,
I am currently working on a custom index model that shows YouTube videos from the shops related channel. I have the code working outside of Phoenix but I'm looking at how to add it in.
I know how to duplicate the module and get that to show, what I'm struggling with is where to put the code for the function that fetches the videos - see below.
I am currently working on a custom index model that shows YouTube videos from the shops related channel. I have the code working outside of Phoenix but I'm looking at how to add it in.
I know how to duplicate the module and get that to show, what I'm struggling with is where to put the code for the function that fetches the videos - see below.
Code: Select all
function fetchLatestVideos($apiKey, $channelId, $maxResults = 3) {
$apiUrl = "https://www.googleapis.com/youtube/v3/search?key=$apiKey&channelId=$channelId&part=snippet,id&order=date&maxResults=$maxResults";
$response = file_get_contents($apiUrl);
return json_decode($response, true);
}
$apiKey = ''; // Replace with your YouTube API key
$channelId = ''; // Replace with your YouTube channel ID
$videos = fetchLatestVideos($apiKey, $channelId);
header('Content-Type: application/json');
echo json_encode($videos);