athombv / homey-web-api-issues

This issue tracker is for Homey Developers using the Web API.
4 stars 1 forks source link

Example doesn't work on Web Api documentation page #30

Open wilfred70 opened 1 year ago

wilfred70 commented 1 year ago

I started with

I am getting a blank page, no device is turning on nor off.

Not sure what I am doing wrong here.

Also I would like to have my own clientid/clientsecret, but in the form you won't get it if it's only for personal use. Not sure why that is, as I first try to get it working anyway. In fact I want to create a dashboard integrating Homey but also other stuff.

jleufven commented 1 year ago

Yeah, I'm stuck with the same thing. The example doesn't work.

I'm toying around with a personal app that I'd like to try some things with. But got stuck when trying the documented example. It just says Unable to initialize app APIError: The access token was not found.

ramonout commented 1 year ago

@wilfred70 i'm trying the same at the moment. really missing a way to create a nice dashboard and was thinking to create an webpage that does api calls to get the data from homey. Any luck from your end by now?

LAGit commented 1 year ago

I also had a hard time getting this to behave and I think the documentation is a little bit poor when it comes to this.. Also, I learned that you must run the code in localhost, port 80. Port 443 or any other port number does not seem to work. Please try the following, it works for me.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="https://cdn.athom.com/homey-api/3.0.2.js"></script>
    <script>
        window.onload = function (e) {
            const cloudApi = new window.AthomCloudAPI({
                clientId: '5a8d4ca6eb9f7a2c9d6ccf6d',
                clientSecret: 'e3ace394af9f615857ceaa61b053f966ddcfb12a',
                redirectUrl: 'http://localhost'
            });

            const loggedIn = cloudApi.isLoggedIn();

            if (!loggedIn) {
                if (cloudApi.hasAuthorizationCode()) {
                    const token = cloudApi.authenticateWithAuthorizationCode();
                } else {
                    window.location.href = cloudApi.getLoginUrl();
                }
            }
            console.log(cloudApi);

            cloudApi.getAuthenticatedUser().then(function (user) {
                console.log(user);
                document.getElementById('fullname').innerHTML = user.fullname;
            });
        }
    </script>
</head>
<body>
    <div id="fullname"></div>
</body>
</html>