Hey,
I've been trying this for several hours now.. I'm trying to show someone's Steam name, but it doesn't work.
Code:
[CODE]<?php
$id = $_GET["steamid"];
$link = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=WEB-API-KEY-N-STUFF&steamids=' . $id . '&format=json');
$myarray = json_decode($link, true);
?>
<div id="playerinfo">
<h1 id="name">Welcome, <?php print $myarray['response']['players'][0]['personaname']; ?>!</h1>[/CODE]
Yes, I did put ?steamid=%s in the URL. Anyone notice what's wrong?
Edit:
Apparently I have to keep my key a secret. But yes, I do have an API key in there.
maybe [url=http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen]allow_url_fopen[/url] isn't enabled. you can also try looking into [url=http://www.php.net/manual/en/function.curl-exec.php#refsect1-function.curl-exec-examples]cURL[/url].
[editline]6th May 2014[/editline]
you can always revoke the API key and re-request it and you will generate a new one.
[editline]6th May 2014[/editline]
next time please post [url=http://facepunch.com/showthread.php?t=1250244]Questions That Don't Need Their Own Thread v4[/url]
Well, you have to convert the %s to the steam id.
[code]
$communityid = $_GET["steamid"];
//See if the second number in the steamid (the auth server) is 0 or 1. Odd is 1, even is 0
$authserver = bcsub($communityid, '76561197960265728') & 1;
//Get the third number of the steamid
$authid = (bcsub($communityid, '76561197960265728')-$authserver)/2;
//Concatenate the STEAM_ prefix and the first number, which is always 0, as well as colons with the other two numbers
$steamid = "STEAM_0:".$authserver.":".$authid;
[/code]
[QUOTE=dexon;44739831]Well, you have to convert the %s to the steam id.
[code]
$communityid = $_GET["steamid"];
//See if the second number in the steamid (the auth server) is 0 or 1. Odd is 1, even is 0
$authserver = bcsub($communityid, '76561197960265728') & 1;
//Get the third number of the steamid
$authid = (bcsub($communityid, '76561197960265728')-$authserver)/2;
//Concatenate the STEAM_ prefix and the first number, which is always 0, as well as colons with the other two numbers
$steamid = "STEAM_0:".$authserver.":".$authid;
[/code][/QUOTE]
This is what I thought at first, but the API actually takes the community id, so getting the steamid (unless you want to show it to the player, or use it later) is actually pointless.
I also think that it may be problem of file_get_contents. OP should try using cURL, to see if it keeps happening.
Ohh yea you're right :)
my bad, nvm then.
What error do you get? (Try setting a lower error_reporting level like E_ALL)
If you get no error, what is the value of $link or $myarray ?
Sorry, you need to Log In to post a reply to this thread.