I created a website with 3rd party API (YouTube) where I’m fetching the data of the youtube channel,
The problem is my website not showing any result on my repeater without any error &
on the console it shows https://www.googleapis.com/youtube/v3/channels?part=statistics,snippet,brandingSettings&id=" + undefined + “&key=” + apiKey
Here is my backend code:
import { fetch } from 'wix-fetch';
import wixData from 'wix-data';
export async function getData() {
const apiKey = "Api Key";
let index = 0;
let cId = wixData.query("YtChannels", "chId") // chId is the field name where i store channel id's
.find()
.then((results) => {
while (index <= results.items.length - 1) {
let channelId = (results.items[index].chId);
index++;
}
});
const response = await fetch("https://www.googleapis.com/youtube/v3/channels?part=statistics,snippet,brandingSettings&id=" + cId + "&key=" + apiKey, {
method: 'get'
});
if (response.status >= 200 && response.status < 300) {
const res = await response.json();
return res;
}
let res = await response.json();
return res;
}
Here is my frontend code:
import { getData } from 'backend/youtube.jsw';
export function channelRepeater_itemReady($item, itemData, index) {
$w.onReady(function () {
getData()
.then((response) => {
let data = response;
data.forEach((item) => {
item._id = String(index++);
})
$item('#channelRepeater').data = itemData;
//Channel Name
let channelName = data.items[0].snippet.title;
$item("#channelName").text = itemData.channelName;
//Channel Logo
let channelLogo = data.items[0].snippet.thumbnails.medium.url;
$item("#channelLogo").src = itemData.channelLogo;
//Subscriber Confirmation Button
let subConfirm = ('href', 'https://www.youtube.com/channel/' + data.items[0].id + '?sub_confirmation=1');
$item("#subsLink").link = itemData.subConfirm;
// Live Subscriber Count
let subCount = data.items[0].statistics.subscriberCount;
$item("#liveCount").text = itemData.subCount;
})
// Subscriber Refresing
$w.onReady(function () {
setInterval(() => {
getData()
.then((response) => {
let subCount = response.items[0].statistics.subscriberCount;
$item("#liveCount").text = itemData.subCount;
});
}, 2000); //2000 milliseconds
});
});
}
#repeater #database api
Any idea @givemeawhisky @Yisrael (Wix) @Code Queen Nayeli