06-10-2024, 02:31 PM
Hi
The problem is lack of authorization. Exactly the same as pasting the api address and not confirming it
"{"error":{"message":"unauthorized"}}"
The ability to read it in HTML is very simple
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reading data from API</title>
</head>
<body>
<h1>API</h1>
<div id="data-container">
<p>Loading...</p>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
const url = "https://backend.thinger.io/v3/users/.....";
const token = "eyJhbGci...........";
fetch(url, {
method: 'GET',
headers: {
'Authorization': 'Bearer' + token
}
})
.then(response => response.json())
.then(date => {
const dataContainer = document.getElementById('data-container');
dataContainer.innerHTML = `
<p>temp1: ${data.temp1}°C</p>
<p>temp2: ${data.temp2}°C</p>
`;
})
.catch(error => {
console.error('Error:', error);
document.getElementById('data-container').innerHTML = '<p>error</p>';
});
});
</script>
</body>
</html>
but unfortunately I don't know how to read this data in the application.
The problem is lack of authorization. Exactly the same as pasting the api address and not confirming it
"{"error":{"message":"unauthorized"}}"
The ability to read it in HTML is very simple
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reading data from API</title>
</head>
<body>
<h1>API</h1>
<div id="data-container">
<p>Loading...</p>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
const url = "https://backend.thinger.io/v3/users/.....";
const token = "eyJhbGci...........";
fetch(url, {
method: 'GET',
headers: {
'Authorization': 'Bearer' + token
}
})
.then(response => response.json())
.then(date => {
const dataContainer = document.getElementById('data-container');
dataContainer.innerHTML = `
<p>temp1: ${data.temp1}°C</p>
<p>temp2: ${data.temp2}°C</p>
`;
})
.catch(error => {
console.error('Error:', error);
document.getElementById('data-container').innerHTML = '<p>error</p>';
});
});
</script>
</body>
</html>
but unfortunately I don't know how to read this data in the application.