1

i was trying to google but I did'nt see something that helped me.

i'm using the Planetteamspeak API. For Example, I can do:

GET https://api.planetteamspeak.com/serverstatus/1.2.3.4:9987/

An example output is:

    {
  "status": "success",
  "result": {
    "name":      "Planet TeamSpeak",
    "users":     91,
    "slots":     512,
    "online":    true,
    "password":  false
  }
}

Can anyone give me a simple way to show this in an HTML/PHP table like this?

http://cdn.treudler.net/shared/screenshots/capture_20-01-2015-05-56-27.png

I'm a noob in Restful API's :c thank you so much!!!

Joshua2504
  • 11
  • 2

5 Answers5

0
<?php 
    $server = $_GET['serverstatus'];
    $result = file_get_contents('https://api.planetteamspeak.com/serverstatus/'.$server.'/');
    $result = json_decode($result);
?>

<h2>Server status</h2>
<table border=1>
    <tr><td>Status</td><td><?=$result->status;?></td></tr>
    <tr><td>Name</td><td><?=$result->result->name;?></td></tr>
    <tr><td>Users</td><td><?=$result->result->users;?></td></tr>
    <tr><td>Slots</td><td><?=$result->result->slots;?></td></tr>
    .....
</table>

<!-------------------------------------------------------->

<?php 
    $server = $_GET['servernodes'];
    $result = file_get_contents('https://api.planetteamspeak.com/servernodes/'.$server.'/');
    $result = json_decode($result);
?>

<h2>Server Nodes</h2>
<table border=1>
    <tr><td>Status</td><td><?=$result->status;?></td></tr>
    <tr><td>Name</td><td><?=$result->result->name;?></td></tr>
    <tr><td>Users</td><td><?=$result->result->users;?></td></tr>
    <tr><td>Slots</td><td><?=$result->result->slots;?></td></tr>
    .....
</table>

<!-------------------------------------------------------->
.... add as many variables / sections as you wish

The way to call the script:
https://ovh.treudler.net/api/index.php?serverstatus=1.2.3.4:9987&servernodes=1.4.6.8:9987

Keep adding &variable=value to the URL as many times as you please

Oleg Dubas
  • 2,320
  • 1
  • 10
  • 24
  • Thanks for help! I'm a big noob with API's and I still don't understand how it works. I don't even know how I can use GET in PHP ._. Would be so nice if you can share a complete script with me.. :c – Joshua2504 Jan 20 '15 at 05:10
  • Thank you so much!! the URL of my script is https://ovh.treudler.net/api/index.php Can I do something like https://ovh.treudler.net/api/index.php?serverstatus=1.2.3.4:9987 ? :) – Joshua2504 Jan 20 '15 at 05:16
  • omg thank you! i have one last thing :D I want to add multiple requests. GET https://api.planetteamspeak.com/servernodes/82.211.30.15:9987/ and https://ovh.treudler.net/api/index.php?serverstatus=1.2.3.4:9987?servernodes=1.4.6.8:9987 etc... is that possible? – Joshua2504 Jan 20 '15 at 05:23
  • Can you please add the lines? :c – Joshua2504 Jan 20 '15 at 05:27
  • I need to wait 90 minutes... Can you help me? :/ – Joshua2504 Jan 20 '15 at 05:35
  • okay. at the moment i can do ?serverstatus=1.2.3.4 to use https://api.planetteamspeak.com/serverstatus/ i want to add more like ?serverhistory=1.2.3.4 and ?clienthistrory=1.2.3.4 to use https://api.planetteamspeak.com/serverhistory and more sorry for my english... – Joshua2504 Jan 20 '15 at 05:39
  • I dont know why but that doesnt work for me... here are the example outputs: https://www.planetteamspeak.com/rest-api/ (i want to use the server history because i dont have premium account ^^) – Joshua2504 Jan 20 '15 at 05:55
  • Updated. Please edit tables / access the results yourself from now, I think I have answered your initial question. Learn to do it, or pay someone to do it. – Oleg Dubas Jan 20 '15 at 05:58
0

I'm assuming $response is the response back from the rest call.

    <?php
 $response= file_get_contents('https://api.planetteamspeak.com/serverstatus/82.211.30.15:9987/%22');
$response = json_decode($response);
?>

    <table style="width:100%">
  <tr>
    <td>General Information</td>
  </tr>
  <tr>
    <td>Name:  <?php echo $response->result->name;?></td>
  </tr>
  <tr>
    <td>Status:  <?php if($response->result->online == true){echo "Online";}else{echo "Offline";}?></td>
  </tr>
  <tr>
    <td>Users Online:  <?php echo $response->result->users;?></td>
  </tr>
  <tr>
    <td>Users Online:  <?php echo $response->result->users;?></td>
  </tr>
  <tr>
    <td>Flags:  </td>
  </tr>
 <tr>
    <td>Last Update: <?php echo getdate()?> </td>
  </tr>
</table> 
Asheliahut
  • 901
  • 6
  • 11
0
<?php $result = json_decode($data,true)?>

<table border=1>
    <tr><td>Status</td><td><?php echo $result['status'];?></td></tr>
    <tr><td>Name</td><td><?php echo $result['name'];?></td></tr>
    <tr><td>Users</td><td><?php echo $result['users'];?></td></tr>
    <tr><td>Slots</td><td><?php echo $result['slots'];?></td></tr>
    .....
</table>
ABIRAMAN
  • 929
  • 8
  • 12
0

I can't comment but I've been reading your comments here and realize that you may not actually know how to send the request itself in order to receive the data in the first place. There are a few ways which are outlined pretty well in answers to this question. How to send a GET request from PHP?

Community
  • 1
  • 1
-1

Planetteamspeak API returns Data in Json Format

you can do like this to get json data to array

$resultData = json_decode($data);

and then use HTML table and display data in it with PHP

echo $resultData->result->name;
kamlesh.bar
  • 1,774
  • 19
  • 38