Yahoo Weather API Работает по HTTP, но не по HTTPS?

Так что у меня есть сайт, где я хочу отображать погоду. Код, который я имею (показанный ниже), прекрасно работает, когда у меня есть $base_url переменная установлена ​​следующим образом:

$base_url = "http://query.yahooapis.com/v1/public/yql";

Но всякий раз, когда я переключаю его на https (показано ниже), я внезапно получаю следующую ошибку:

Notice: Trying to get property of non-object in C:\xampp\htdocs\scheduling.r60\reports\include\weather.php on line 18

Чтобы уточнить, я использую XAMPP для проверки этого, но когда я проверяю это на живом веб-сайте, он также не работает (у живого сайта действительно есть действительный сертификат SSL и применяется HTTPS).

<?php

$base_url = "https://query.yahooapis.com/v1/public/yql";
$yql_query = "select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='mundelein, il')";
$yql_query_url = $base_url . "?q=" . urlencode($yql_query) . "&format=json";

// Making call with cURL
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($session);

// Convert JSON to PHP Object
$phpObj = json_decode($json);

print_r($phpObj);

// Getting necessary content
$cityInfo = $phpObj->query->results->channel->location->city . ", " . $phpObj->query->results->channel->location->region;
$currentDate = $phpObj->query->results->channel->item->condition->date;
$currentTemperature = $phpObj->query->results->channel->item->condition->temp;
$currentText = $phpObj->query->results->channel->item->condition->text;
$currentHigh = $phpObj->query->results->channel->item->forecast[0]->high;
$currentLow = $phpObj->query->results->channel->item->forecast[0]->low;

$dayOneDay = $phpObj->query->results->channel->item->forecast[1]->day;
$dayOneHigh = $phpObj->query->results->channel->item->forecast[1]->high;
$dayOneLow = $phpObj->query->results->channel->item->forecast[1]->low;

$dayTwoDay = $phpObj->query->results->channel->item->forecast[2]->day;
$dayTwoHigh = $phpObj->query->results->channel->item->forecast[2]->high;
$dayTwoLow = $phpObj->query->results->channel->item->forecast[2]->low;

$dayThreeDay = $phpObj->query->results->channel->item->forecast[3]->day;
$dayThreeHigh = $phpObj->query->results->channel->item->forecast[3]->high;
$dayThreeLow = $phpObj->query->results->channel->item->forecast[3]->low;

$dayFourDay = $phpObj->query->results->channel->item->forecast[4]->day;
$dayFourHigh = $phpObj->query->results->channel->item->forecast[4]->high;
$dayFourLow = $phpObj->query->results->channel->item->forecast[4]->low;

if($currentText == "Partly Cloudy") {
$picture = "../reports/assets/imgs/weather/partly-cloudy_png.png";
}elseif($currentText == "Fog") {
$picture = "/reports/assets/imgs/weather/fog_png.png";
}elseif($currentText == "Cloudy") {
$picture = "/reports/assets/imgs/weather/partly-cloudy_png.png";
}elseif($currentText == "Mostly Cloudy") {
$picture = "/reports/assets/imgs/weather/mostly-cloudy_png.png";
}elseif($currentText == "Rain"){
$picture = "/reports/assets/imgs/weather/rain_png.png";
}elseif($currentText == "Sleet and Freezing Rain"){
$picture = "/reports/assets/imgs/weather/sleet-freezing-rain_png.png";
}elseif($currentText == "Freezing Rain"){
$picture = "/reports/assets/imgs/weather/sleet-freezing-rain_png.png";
}elseif($currentText == "Sleet"){
$picture = "/reports/assets/imgs/weather/sleet-freezing-rain_png.png";
}elseif($currentText == "Light Rain") {
$picture = "/reports/assets/imgs/weather/light-rain_png.png";
}elseif($currentText == "Fair") {
$picture = "/reports/assets/imgs/weather/fair_png.png";
}else{
$picture = "../reports/assets/imgs/weather/sunny_png.png";
}

?>

<div class="card">
<div class="card-title">Weather for <?php echo $cityInfo; ?></div>
<div class="card-content">
<center><?php echo $currentDate; ?></center>
<br />
<div class="row">
<div class="col-xs-6 col-sm-6" style="text-align: center; padding-top: 5%;">
<h1 style="margin: 0px; padding: 0px; font-size: 25pt;"><?php echo $currentTemperature; ?>&deg;F</h1>
<h2 style="margin: 0px; padding: 0px; font-size: 20pt; font-weight: 400;"><?php echo $currentText; ?></h2>
<b><h3 style="margin: 0px; padding: 0px; font-size: 10pt; font-weight: 400;">High: <?php echo $currentHigh; ?>&deg;F / Low: <?php echo $currentLow; ?>&deg;F</h3></b>
</div>
<div class="col-xs-6 col-sm-6">
<center><img src="<?php echo $picture; ?>" style="width: 100%;" /></center>
</div>
</div>
<hr>
<div class="row">
<div class="col-md-12">
<?php echo $dayOneDay; ?>
<span style="float: right;">
High: <?php echo $dayOneHigh; ?>&deg;F
/
Low: <?php echo $dayOneLow; ?>&deg;F
</span>
</div>
<div class="col-md-12">
<?php echo $dayTwoDay; ?>
<span style="float: right;">
High: <?php echo $dayTwoHigh; ?>&deg;F
/
Low: <?php echo $dayTwoLow; ?>&deg;F
</span>
</div>
<div class="col-md-12">
<?php echo $dayThreeDay; ?>
<span style="float: right;">
High: <?php echo $dayThreeHigh; ?>&deg;F
/
Low: <?php echo $dayThreeLow; ?>&deg;F
</span>
</div>
<div class="col-md-12">
<?php echo $dayFourDay; ?>
<span style="float: right;">
High: <?php echo $dayFourHigh; ?>&deg;F
/
Low: <?php echo $dayFourLow; ?>&deg;F
</span>
</div>
</div>
</div>
<div class="card-footer">
<a href="http://www.weather.com/weather/today/l/60060:4:US" class="button-flat right" target="_blank">Full Report</a>
<div class="clear"></div>
</div>
</div>

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]