Art-of-WiFi / UniFi-API-browser

Tool to browse data exposed by Ubiquiti's UniFi Controller API
MIT License
1.1k stars 150 forks source link

Beginner needs help. #34

Closed mg1142mg closed 7 years ago

mg1142mg commented 7 years ago

EDITS: Last error_log: [10-Jul-2017 03:17:03 UTC] cURL error: Failed to connect to 127.0.0.1 port 8443: Connection refused [10-Jul-2017 03:17:03 UTC] PHP Catchable fatal error: Object of class UnifiApi could not be converted to string in /home/mikael1142/public_html/guest/s/default/auth.php on line 34

Hello guys, first of all, thank you very much for the api, I am sure it will be very useful to me when rightly used!

However, and as you can imagine, I have troubles in using the php class. Can you please guide me on what I am doing wrong here? (I know it's not stackoverflow, but I sense that you can help me in a substantially more efficient way...)

if($prenom && $gender) {
                //Minutes to authorize, change to suit your needs
                $minutes = 240;
                $login = new UnifiApi();
                $login->login();
                $authorize_guest = new UnifiApi();
                $authorize_guest->authorize_guest($mac, $minutes);
                $logout = new UnifiApi();
                $logout->logout();
                if($authorize_guest === true) {
                        header("Location: https://www.google.ch");
                }
                else {
                        $error_log = new UnifiApi();
                        $error_log->get_last_error_message();
                        echo $error_log;
                }

        }

I would understand that you don't want to get into this piece of code or explaining me why my php is wrong. If that's the case, could you redirect me to good material in order for me to correct my beginner mystakes?

Thanks!

malle-pietje commented 7 years ago

Welcome here. Take a look at the examples and you will quickly learn how to create a new instance of UnifiApi (with the required parameters). Eg.

$unifidata = new UnifiApi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
malle-pietje commented 7 years ago

There are also quite some a lot of other errors in your code; just try to start off with one of the examples and expand from there. Step by step...

mg1142mg commented 7 years ago

Alright.. The thing is, I did that out of my head and hoped it would work. Would do as you suggested and come back here for issues I encounter.. Thanks for your replies!

malle-pietje commented 7 years ago

Ok, good luck!:thumbsup: