Question

I have the following php code to get a json file from the steam web api. I can't seem to figure out why this isn't recieving any information. Any help would be appreciated.

Please use your own steam api key.

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
    <p>Welcome! <?php echo $_GET["fname"]; ?></p>
    <p>Your steam id is 
<?php
$username = $_GET["fname"];
$devKey = '<Insert Dev Key>';
$json_url = 'http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=' . $devKey . '&vanityurl=' . $username;
echo $json_url;
$json_output = json_decode ( $json_url, true );
echo $json_output['response']['steamid'];

?>
</p>
</body>
</html>
Was it helpful?

Solution

You aren't requesting anything from the url, you're trying to json_decode the url itself.

Instead try something like:

$json_url = 'http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=' . $devKey . '&vanityurl=' . $username;
$res = file_get_contents($json_url);
$json_output = json_decode ( $res, true );
var_dump($json_output);

Also have a look into curl as this is more powerful when dealing with apis.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top