Reanne.5462 Posted January 15, 2018 Share Posted January 15, 2018 <?php $url = "https://api.guildwars2.com/v2/commerce/prices/19684"; $string = file_get_contents($url); $next = json_decode($string, true); $response = array($next); foreach ($response as $value) { echo var_dump($value); } This results in NULL instead of the expected results. Why? What has changed since last time I was working on this API? Link to comment Share on other sites More sharing options...
Eearslya.6309 Posted January 15, 2018 Share Posted January 15, 2018 eearslya@chimera ~ $ php temp.phparray(4) { ["id"]=> int(19684) ["whitelisted"]=> bool(false) ["buys"]=> array(2) { ["quantity"]=> int(362705) ["unit_price"]=> int(79) } ["sells"]=> array(2) { ["quantity"]=> int(1887746) ["unit_price"]=> int(95) }}Works just fine for me. First thing I'd do is dump $string to the console, and make sure that you're not encountering an error with file_get_contents(). Link to comment Share on other sites More sharing options...
smiley.1438 Posted January 15, 2018 Share Posted January 15, 2018 Should work as expected, except that the API times out every now and then so that file_get_contents() returns false and everything breaks.Check if there's a valid response like so:$response = file_get_contents('https://api.guildwars2.com/v2/commerce/prices/19684');if($response !== false){ $response = json_decode($response); foreach($response as $key => $value) { var_dump(['key' => $key, 'value' => $value]); }}else{ // handle error} Link to comment Share on other sites More sharing options...
Reanne.5462 Posted January 15, 2018 Author Share Posted January 15, 2018 Ok, thanks for the help - I am pretty sure I found the problem - I think it has to do with the ssl and file_get_contents. I will need to mess with my php.ini as soon as I find time. Yeah, its definitely my server problem, not the API :anguished: Link to comment Share on other sites More sharing options...
Reanne.5462 Posted January 15, 2018 Author Share Posted January 15, 2018 I'm not gonna be able to do this using localhost anymore am I? Am I right in that I will need a Server Certificate? Link to comment Share on other sites More sharing options...
smiley.1438 Posted January 16, 2018 Share Posted January 16, 2018 try this https://github.com/codemasher/php-oauth/blob/master/src/HTTP/StreamClient.php#L93 (that whole thing includes a GW2 API wrapper btw. and does everything that is required for a proper connection) Link to comment Share on other sites More sharing options...
DragonHeart.7201 Posted January 17, 2018 Share Posted January 17, 2018 @Reanne.5462 said:I'm not gonna be able to do this using localhost anymore am I? Am I right in that I will need a Server Certificate?You won't need a server certificate and you still should be able to use it for local network purposes. Not exactly sure why you think this wouldn't work. Been doing similar with my own stuff and works fine. Link to comment Share on other sites More sharing options...
smiley.1438 Posted January 17, 2018 Share Posted January 17, 2018 cacaert.pem != server certificate btw. and the cacert is what you need for cURL (or file_get_contents) and SSL Link to comment Share on other sites More sharing options...
Reanne.5462 Posted January 18, 2018 Author Share Posted January 18, 2018 my scripts work fine on a paid host, but I can't seem to get them to work on my win10 iis - I used the localhost for more convenience, but I don't want to spend hours trying to figure my home server out, I'll just use my other host :) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.