So I’ve set debug to true, and it is throwin me some strange errors that doesn’t appear without it, and is breaking the site.
I’ve got this route
array(
"pattern" => "api/yt",
"method" => "GET",
"action" => function() {
$api_src = c::get("api.youtube.channel.src") . c::get("api.youtube.key");
$api_src_alt = c::get("api.youtube.channel2.src") . c::get("api.youtube.key");
$api_alt = json_decode(file_get_contents($api_src_alt));
$api = json_decode(file_get_contents($api_src));
$views = $api->items[0]->statistics->viewCount + $api_alt->items[0]->statistics->viewCount;
$videos = $api->items[0]->statistics->videoCount + $api_alt->items[0]->statistics->videoCount;
$subscribers = $api->items[0]->statistics->subscriberCount + $api_alt->items[0]->statistics->subscriberCount;
return response::json(array(
"views" => array(
"main" => $api->items[0]->statistics->viewCount,
"services" => $api_alt->items[0]->statistics->viewCount,
"total" => $api->items[0]->statistics->viewCount + $api_alt->items[0]->statistics->viewCount
),
"videos" => array(
"main" => $api->items[0]->statistics->videoCount,
"services" => $api_alt->items[0]->statistics->videoCount,
"total" => $api->items[0]->statistics->videoCount + $api_alt->items[0]->statistics->videoCount
),
"subscribers" => array(
"main" => $api->items[0]->statistics->subscriberCount,
"services" => $api_alt->items[0]->statistics->subscriberCount,
"total" => $api->items[0]->statistics->subscriberCount + $api_alt->items[0]->statistics->subscriberCount
)
));
}
),
which gives me this json response as I want
debug = off
{
"views": {
"main": "37519",
"services": "7163",
"total": 44682
},
"videos": {
"main": "48",
"services": "22",
"total": 70
},
"subscribers": {
"main": "184",
"services": "35",
"total": 219
}
}
And I pull that json response with file_get_contents()
and then json_decode()
it, which works fine, and gives me the outputs I want
debug = off
$api = json_decode(file_get_contents($site->url()."/api/yt"));
echo $api->views->total; //44682
echo $api->videos->total; //70
but when I turn on debug mode, I get this
debug = on
Notice: Trying to get property of non-object in /Volumes/TheWiseGrey/WebServer/gsponsor.dev/site/templates/home.php on line 35
I’m using Kirby 2.2.3