Hi
Ive taken over a website that has used json data from Wunderground for years but the new limits are causing issues for us. We hit the API limit and the widget is broken till the limit resets
I want to convert our current widget we have that parses the Wunderground API and start using the Davis API
Im no developer though. Any suggestions on how to convert the code ? The Davis API isnt very well documented
Here is the section of the header file that goes to get the data from API and then parse it and display just the temp, wind speed, wind direction and observation time
Im guessing the issue is with the authorization or postman token but I cant find any details on how that works
Im no Curl expert
Thanks in advance for your help and time
<div class="weather_topdata">
<?php
$curl = curl_init();
// wunderground $url= "
https://api.weather.com/v2/pws/observations/current?stationId=Kxx&format=json&units=e&apiKey=xxxxxxxxxxxx";
//davis URL
$url= "
https://api.weatherlink.com/v1/NoaaExt.json?user=xxA&pass=xxher&apiToken=xxxxxxxxxx";
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(
"authorization: Basic xxx6YWRtaW4=",
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded",
"postman-token: xxx-1882-403a-xxxxx-xxxxx1e05"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$json_decode = json_decode($response);
}
// echo "<pre>";
//print_r($json_decode);
// echo "</pre>";
foreach ($json_decode as $key=>$val) {
//$a = (object)$val;
// Wunderground API
/* $temp_f=$val[0]->imperial->temp;
//$temp_f=$val[0]->imperial->tempHigh;
//$wind_speed=$val[0]->imperial->windspeedHigh;
$wind_speed=$val[0]->imperial->windSpeed;
$wind_high_gust=$val[0]->imperial->windGust;
$obs_time=$val[0]->obsTimeLocal;
$wind_dir=$val[0]->winddir; */
// davis weather link API
$temp_f=$val[0]->imperial->temp_f;
$wind_speed=$val[0]->imperial->wind_mph;
$wind_dir=$val[0]->imperial->wind_dir;
$wind_deg=$val[0]->imperial->wind_degrees;
$wind_high_gust=$val[0]->imperial->wind_ten_min_gust_mph;
$obs_time=$val[0]->observation_time;
}