Hey Guys, since everyone wants to learn how to build and use the API, i figured i'd create a collective question/answer thread. My goal is for developers to help people by giving code samples or explanations of how to make something work. I know we all have big dreams of what we want to accomplish, so let's put our heads together and make some truly awesome things!
Couple things to note: 1) Please include which language you're coding in. PHP, Python, mSL, whatever it may be. 2) If you're having issues with code, make sure to include the code you're using, as well as what you're trying to accomplish. 3) Never include your API key in the post.
Good luck guys! I'll continue to be active here and in the sub-forum as much as i can to help you guys along.
A basic example of how to use the API: <html> <head> <title>Simple Form and API Tutorial</title> </head> <body> <form method="POST" action="<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; ?>"> <p>ID: <input type="text" id="user_id" name="user_id"></p> <p><input type="submit" name="Submit" value="Submit"></p> </form> <?php if(isset($_POST['user_id'])) { $apikey = ''; // Your API key $user_id = $_POST['user_id']; $url = "http://api.torn.com/user/$user_id?selections=profile&key=$apikey"; // URL to get the user's profile contents $json = file_get_contents($url); // Read the JSON response from the server $data = json_decode($json, true); // Convert JSON into a PHP array } ?> <pre> <?php print_r($data); ?> </pre> Name: <?php echo $data['name']; ?> </body></html>
Recursive search of your bazaar with items Qty and price: <?php foreach($outputPublic['bazaar'] as $key=>$val){ echo ($val['quantity']."x ".$val['name']." @ $". $val['price'].", (M: $".$val['market_price'].")<br>");}?>" href="http://www.torn.com/bazaar.php?userID=<?php echo($outputPublic["player_id"].'">'.$bazaarCounted. ' items in Bazaar</a>');?>
uhms okay, I asked bc if it runs with django, seems logic to me to run in Ruby Rails... (easier to me to program on ruby.... but I will not reject to learn another language)
I'm not familiar with Ruby at all, but if it has a way to interpret JSON, then you'll be fine to build w/e you want in Ruby. If it doesn't have a way to interpret JSON, then you're going to have to find someone who did the work of building a library for you, or make you're own. Either way, JSON is pretty universal and can be used by most programming languages in one way or another.