Get a JSON from url with PHP -


im new php , tried json object twitch api retrieve 1 of values , output it. i.e

i need information link: https://api.twitch.tv/kraken/users/username/follows/channels/channelsname

plus need to can modify urls username , channelsusername. want api call howlong user xy following channelxy , called using nightbots $customapi function.

the date need json "created_at"

since able clear out errorsheres final php file works if encounters similiar errors:

<?php  $url = "https://api.twitch.tv/kraken/users/" . $_get['username'] . "/follows/channels/" . $_get['channel'];  $result = file_get_contents($url); $result = json_decode($result, true);  echo $result["created_at"]; ?> 

you have typo in code on first line , you're not storing result of json_decode anywhere.

<?php $url = "https://api.twitch.tv/kraken/users/" . $_get['username'] . "/follows/channels/" . $_get['channel'];  $result = file_get_contents($url); $result = json_decode($result, true);  echo $result["created_at"]; 

you have call page way page.php?username=yeroise&channel=ceratia in order output created_at value user , channel.

in code you're using 2 different ways content of page , need 1 (either file_get_contents or using curl), chose file_get_contents here other method adds complexity no reason in case.


Comments