Jump to content

cURL, Wargaming API


davidg
Go to solution Solved by ignace,

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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.