davidg Posted December 9, 2013 Share Posted December 9, 2013 Hi there, I'm looking for a way how to obtain data for World of tanks account. I'm using Wargaming API and cURL. Address example with data looks like this: http://api.worldoftanks.eu/2.0/account/info/?application_id=d0a293dc77667c9328783d489c8cef73&account_id=509662813 With little php manual help I came up with (ehm copied) this. <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://api.worldoftanks.eu/2.0/account/info/?application_id=d0a293dc77667c9328783d489c8cef73&account_id=509662813"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $json = json_decode($output); echo $json->{'data'}->{509662813}->{'statistics'}->{'all'}->{'battles'}; ?> It doesn't work but when I copy the contents of address to txt file and save it on my webhosting and then use the cURL - it works. I tried to use CURLOPT_CONNECTTIMEOUT because sometimes it takes a long time to load a page from API. It didn't work either. What am I missing here? Link to comment https://forums.phpfreaks.com/topic/284643-curl-wargaming-api/ Share on other sites More sharing options...
ignace Posted December 9, 2013 Share Posted December 9, 2013 echo $json->data->{'509662813'}->statistics->all->battles; Link to comment https://forums.phpfreaks.com/topic/284643-curl-wargaming-api/#findComment-1461765 Share on other sites More sharing options...
davidg Posted December 9, 2013 Author Share Posted December 9, 2013 OK thank you, echo line is corrected but problem remains. It doesn't work with wargaming address. It only works if I copy the data to txt file and upload it to my hosting. Link to comment https://forums.phpfreaks.com/topic/284643-curl-wargaming-api/#findComment-1461767 Share on other sites More sharing options...
ignace Posted December 9, 2013 Share Posted December 9, 2013 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://api.worldoftanks.eu/2.0/account/info/?application_id=d0a293dc77667c9328783d489c8cef73&account_id=509662813"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $json = json_decode($output); echo $json->data->{'509662813'}->statistics->all->battles;Prints: 2579 Try it here: http://phpcodepad.com/ Link to comment https://forums.phpfreaks.com/topic/284643-curl-wargaming-api/#findComment-1461789 Share on other sites More sharing options...
davidg Posted December 9, 2013 Author Share Posted December 9, 2013 It is correct. However it's strange that it works on phpcodepad website but not on my hosting. Probably different php settings. Thanks anyway ;-) Link to comment https://forums.phpfreaks.com/topic/284643-curl-wargaming-api/#findComment-1461802 Share on other sites More sharing options...
ignace Posted December 9, 2013 Share Posted December 9, 2013 Turn on error_reporting, your hosting does not support curl. error_reporting(-1); ini_set('display_errors', 1);At the top of your script. Link to comment https://forums.phpfreaks.com/topic/284643-curl-wargaming-api/#findComment-1461819 Share on other sites More sharing options...
davidg Posted December 10, 2013 Author Share Posted December 10, 2013 I just found out that connections to foreign servers are disabled by default. I added wargaming.eu as a exception and voilà script works. Thanks again for your help I appreciate it. ;-) Link to comment https://forums.phpfreaks.com/topic/284643-curl-wargaming-api/#findComment-1461998 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.