$('body').css( "margin", "20px" );
$('body').css( "padding", "20px" );
document.write ( '<h1> Tik topk profile api</h1 style="text-transform: capitalize;">');
document.write( `
<div id=userNameDiv>
<button for ='userName' onclick='fetchNBAData();' class=ab-normbutton >click here to check api</button>
<h4 id = "apiWorking" style="display:none">API working<h4>
<h4 id = "apiNotWorking" style="display:none">API not working<h4>
</div> `)
async function fetchNBAData() {
const url = 'https://tiktok82.p.rapidapi.com/getProfile?username=therock';
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': '6d53014b39msheb57d0302282eefp1eeb03jsn32d8c5a9bcba',
'X-RapidAPI-Host': 'tiktok82.p.rapidapi.com'
}
};
try {
const response = await fetch(url, options);
console.log(response);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const result = await response.json(); // Assuming the API returns JSON
console.log('Hello World tiktok API working :', result);
document.getElementById("apiWorking").style.display = "block";
} catch (error) {
document.getElementById("apiNotWorking").style.display = "block";
console.error('Fetch error:', error);
}
}
//fetchNBAData();