via de browser krijg ik deze output
Code: Selecteer alles
[{"id":5695,"attributes":{"batteryLevel":53.0,"distance":0.0,"totalDistance":5.09,"motion":false},"deviceId":1,"type":null,"protocol":"osmand","serverTime":null,"deviceTime":"2017-09-03T19:31:52.000+0000","fixTime":"2017-09-03T19:31:52.000+0000","outdated":false,"valid":true,"latitude":51.177434,"longitude":2.941404,"altitude":-1.92926,"speed":0.0,"course":63.9844,"address":null,"accuracy":0.0,"network":null}]
de functie welke de gegevens vanuit de api haal in php is deze
de aanroep voor $geg
de functie positions2
Code: Selecteer alles
public static function positions2($cookie) {
return self::curl('/api/positions?','GET',$cookie ,'',array());
}
en de functie curl
Code: Selecteer alles
public static function curl($task,$method,$cookie,$data,$header) {
$res=new stdClass();
$res->responseCode='';
$res->error='';
// $header[]="Cookie: ".$cookie;
$header = array(
'Cookie: '.$cookie,
'Accept: application/json',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::$host.$task);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
if($method=='POST' || $method=='PUT' || $method=='DELETE') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
$data=curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', substr($data, 0, $size), $c) == 1) self::$cookie = $c[1];
$res->response = substr($data, $size);
if(!curl_errno($ch)) {
$res->responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
}
else {
$res->responseCode=400;
$res->error= curl_error($ch);
}
curl_close($ch);
return $res;
}
}