jadelantern Posted June 17, 2014 Share Posted June 17, 2014 Hi guys... I was at home and doing some coding and stumbled across and API for a computer game called Battlefield 4 http://api.bf4stats.com/api/playerInfo?plat=pc&name=1ApRiL&output=js; I was checking it out and it is a LOT of data. I was wondering if its possible to only pull certain data from the API, say for instance you only want to pull your user name, ID, and what game you are playing (those are the top 3 things). How would you pull only those 3 stats and display that information on say a webpage for you? thanks guys JL Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 17, 2014 Share Posted June 17, 2014 (edited) Well, yes and no. The documentation for the API is located here: http://bf4stats.com/api Read through that to determine what parameters to pass to only get the data you want. But, it's likely you will still get more data than you are after. So, just parse the return data to use the data you want to display. The url you provided has an 'output' parameter. Look at the documentation and the available output formats to determine which one you want to work with. EDIT: I don't see anything in the returned data that includes what game the user is playing. <?php //Set player name for the query $playerName = '1ApRiL'; //Get the data in JSON format $raw_data = file_get_contents("http://api.bf4stats.com/api/playerInfo?plat=pc&name={$playerName}&output=json&opt=details"); //Decode the data into an object $data = json_decode($raw_data); //Get player object $playerObj = $data->player; echo "ID: {$playerObj->id}<br>\n"; echo "Name: {$playerObj->name}<br>\n"; ?> Note: the opt=details added to the URL will return only the 'basic' details - which include the name and id. The documentation includes more info on the other parameters that can be used. Edited June 17, 2014 by Psycho Quote Link to comment Share on other sites More sharing options...
jadelantern Posted June 17, 2014 Author Share Posted June 17, 2014 Thank you Psycho didn't know how to get the information i wanted. Is the setup to grab the data the same for any API that you are looking to grab information from?Thank you for your help!JL Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 17, 2014 Share Posted June 17, 2014 Is the setup to grab the data the same for any API that you are looking to grab information from? No. How an API works is totally up to the programmer that creates it (or the requirements they are given). They can make whatever input parameters they think are needed and can have whatever output formats that they want. That's why they (should) have documentation. Quote Link to comment Share on other sites More sharing options...
jadelantern Posted June 17, 2014 Author Share Posted June 17, 2014 !Gotcha! thank you again! JL Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.