ben php ile denedim ama api key girdiniz mi
Evet hocam
function getPrayerTimes(city) {
const apiKey = 'sssss';
const url = `https://api.collectapi.com/pray/all?data.city=${city}`;
fetch(url, {
method: 'GET',
headers: {
'content-type': 'application/json',
'authorization': `apikey ${apiKey}`
}
})
.then(response => response.json())
.then(data => {
if(data && data.result) {
const prayerTimesInfo = `${city} için namaz vakitleri:\nSabah: ${data.result.Fajr}\nGüneş: ${data.result.Sunrise}\nİkindi: ${data.result.Dhuhr}\nAkşam: ${data.result.Asr}\nYatsı: ${data.result.Maghrib}\nGece: ${data.result.Isha}`;
console.log(prayerTimesInfo);
appendMessage('ai', prayerTimesInfo);
textToSpeech(prayerTimesInfo);
} else {
const errorMessage = `Maalesef ${city} için namaz vakitleri alınamadı.`;
appendMessage('ai', errorMessage);
textToSpeech(errorMessage);
}
})
.catch(error => {
console.error('Namaz vakitleri alınırken bir hata oluştu:', error);
const errorMessage = 'Namaz vakitleri alınırken bir hata oluştu.';
appendMessage('ai', errorMessage);
textToSpeech(errorMessage);
});
}