Jump to content

cURL, Wargaming API


davidg

Recommended Posts

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

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.