Jump to content

(PHP) API Call Help


Recommended Posts

Hello, I am trying to retrieve members MP names from a database and display that.
 

Here is the current php code being used:
 

<?php
				$sqlget = 'SELECT * FROM players';
				$sqldata = mysqli_query($dbcon, $sqlget);
						
				while($row = mysqli_fetch_array($sqldata, MYSQLI_ASSOC)){
					$json = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXAABB80E2C4C45E1779B&steamids='.$row['playerid'].'');
					$parsed = json_decode($json);

					foreach($parsed->response->players as $player){
					}
					$online = $player->personastate;
					if ($online == '1'){
						$bcolor = '4px solid #6eea15';
					}
					else{
						$bcolor = '';
					}
					
					$json = file_get_contents('https://api.truckersmp.com/v2/player/'.$row['playerid'].'');
					$data = json_decode($json);
					$mpname = $data->name;
					
					echo'<li id="fleet" >';
							echo "<center><img style='height:auto; width:auto; border:$bcolor;' class='img-circle' src='" . $player->avatarfull . "'></center>";
							echo '<center><p style="margin-top: 65%;">'. $player->personaname . '<p></center>';
							echo '<center><p style="margin-top: 65%;">'. $mpname . '<p></center>';
					echo'</li>';
				}
			?>

 

The error I am currently getting is that the $mpname doesn't contain the correct data needed. (I am new to using all APIs and still learning).

Thank you in advance.

Edited by [TSRVTC] DubStepMad
removed api key for steam

mV7R3Lk.png 

Into Code

Link to comment
Share on other sites

Not calling the API several hundred or tens of times per hour. Earlier I had a simple game map based on the ETS2Map API and TruckersMP API, which within a one minute refreshed several times for several dozen people (about 200-300 queries per minute in total). Access was blocked and the developers were angry at me.

rtrn263.png

Link to comment
Share on other sites

  • DevOps
7 hours ago, WooQash said:

Not calling the API several hundred or tens of times per hour. Earlier I had a simple game map based on the ETS2Map API and TruckersMP API, which within a one minute refreshed several times for several dozen people (about 200-300 queries per minute in total). Access was blocked and the developers were angry at me.


There are better ways of doing things rather than doing 3 req/sec 24/7 against our services. When you hit the api harder than our game servers, yeah, we're gonna notice. It's the internet, play fair. Learn to cache your queries and realize we're not on the same scale as your service probably is. Sure, maybe it's not a lot of load if one person does it, but we don't have just one person queuing and abusing us.  

Traffic Cameras : twitch.tv/kat_pw | Ets2Map : ets2map.com
Kat_pw Status:image.png[CCTV #1] Status:image.png[CCTV #2] Status:image.png[CCTV #3] Status:image.png

Link to comment
Share on other sites

  • DevOps

Again, we're fine with you using our api(s). Just take into consideration it's a shared service with other users. Don't abuse it. When working on a feature, think to yourself, "does this data really change all that much? Maybe I should cache it locally for a week instead of spawning a request every-time I need it." We're not out to get you.. 
 

Traffic Cameras : twitch.tv/kat_pw | Ets2Map : ets2map.com
Kat_pw Status:image.png[CCTV #1] Status:image.png[CCTV #2] Status:image.png[CCTV #3] Status:image.png

Link to comment
Share on other sites

8 minutes ago, Kat_pw said:

Again, we're fine with you using our api(s). Just take into consideration it's a shared service with other users. Don't abuse it. When working on a feature, think to yourself, "does this data really change all that much? Maybe I should cache it locally for a week instead of spawning a request every-time I need it." We're not out to get you.. 
 

Thank you and yeah I will read up on caching.

mV7R3Lk.png 

Into Code

Link to comment
Share on other sites

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