489c01713161208e2a2ca4b016c0010c0a862230
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

1) <?php
2) 
3) require_once dirname(__DIR__).'/config.php';
4) 
Bernd Wurst besserer Debug-Modus, Handh...

Bernd Wurst authored 3 years ago

5) $config['debug'] = false;
6) //$config['debug'] = true;
7) 
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

8) $curl = curl_init();
9) 
10) curl_setopt_array($curl, array(
11)       CURLOPT_RETURNTRANSFER => true,
12)       CURLOPT_ENCODING => "",
13)       CURLOPT_MAXREDIRS => 10,
14)       CURLOPT_TIMEOUT => 30,
15)       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
16)       CURLOPT_HTTPHEADER => array("Content-Type: application/json"),
17)       CURLOPT_CUSTOMREQUEST => "POST"));
18) 
19) 
20) function api_call($path, $data)
21) {
22)     global $curl;
23)     global $config;
24) 
Bernd Wurst besserer Debug-Modus, Handh...

Bernd Wurst authored 3 years ago

25)     if ($config['debug']) {
26)         echo '<pre>API-Call: '.$config['api_url'].$path."\n";
27)         print_r($data);
28)         echo '</pre>';
29)     }
30) 
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

31)     $data['authtoken'] = $config['api_token'];
32)     curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
Bernd Wurst besserer Debug-Modus, Handh...

Bernd Wurst authored 3 years ago

33)     curl_setopt($curl, CURLOPT_URL, $config['api_url'].$path.($config['debug'] ? '?debug' : ''));
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

34) 
35)     $response = curl_exec($curl);
36)     $err = curl_error($curl);
37) 
38)     $ret = @json_decode($response, true);
Bernd Wurst besserer Debug-Modus, Handh...

Bernd Wurst authored 3 years ago

39)     if ($config['debug'] && $ret) {
40)         echo '<pre>API response';
41)         print_r($ret);
42)         echo '</pre>';
43)     }
44)     if ($config['debug'] && (!isset($ret['status']) || $ret['status'] == 'error')) {
45)         echo '<pre>API-Error-Response:';
Bernd Wurst API-Authtoken, Idle-Warnung...

Bernd Wurst authored 3 years ago

46)         echo $response;
Bernd Wurst besserer Debug-Modus, Handh...

Bernd Wurst authored 3 years ago

47)         echo '</pre>';