Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mobile APP + other IOT
#7
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. Sad
Reply


Messages In This Thread
Mobile APP + other IOT - by Buczkowski - 06-03-2024, 08:34 AM
RE: Mobile APP + other IOT - by iliaslamprou - 06-04-2024, 07:29 PM
RE: Mobile APP + other IOT - by Buczkowski - 06-04-2024, 07:51 PM
RE: Mobile APP + other IOT - by iliaslamprou - 06-05-2024, 07:33 PM
RE: Mobile APP + other IOT - by Buczkowski - 06-06-2024, 09:58 AM
RE: Mobile APP + other IOT - by iliaslamprou - 06-09-2024, 07:52 PM
RE: Mobile APP + other IOT - by Buczkowski - 06-10-2024, 02:31 PM
RE: Mobile APP + other IOT - by iliaslamprou - 06-11-2024, 09:35 PM
RE: Mobile APP + other IOT - by Buczkowski - 06-14-2024, 10:07 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)