Magnus Vestergaard
Magnus Vestergaard

Reputation: 88

Load steam applist as JSON file

I've been trying to load the Steam app list from this url "https://api.steampowered.com/ISteamApps/GetAppList/v2/?key=XXXXXXXXXetc." and I've tried all combinations I think, with AJAX, downloading it using PHP, but I haven't been able to find a way that works, hope you can help!

Thanks in advance, Magn0053

Upvotes: 0

Views: 1195

Answers (1)

Twisty
Twisty

Reputation: 30893

Try this:

<?php

$jsonString = file_get_content("https://api.steampowered.com/ISteamApps/GetAppList/v2/?key=XXXXXXXXXetc");

$listArray = json_decode($jsonString, true);
echo "<ul id="listResults">\r\n";
foreach($listArray as $k => $v){
    echo "<li><label>$k</label>: $v</li>\r\n";
}
echo "</ul>\r\n";
?>

This can be done in JQuery too (Example: http://jsfiddle.net/Twisty/be5h65L3/):

$(function(){
    $("#getListBtn").click(function(){
        var url = 'https://api.steampowered.com/ISteamApps/GetAppList/v2/?key=XXXXXXXXXetc&callback=?';

        $.ajax({
            type: 'GET',
            url: url,
            async: false,
            jsonpCallback: 'jsonCallback',
            contentType: "application/json",
            dataType: 'jsonp',
            success: function(data) {
               $.each(data, function(k, v){
                   $("#listResults").append("<li><label>" + k + "<label>: " + v + "</li>");
               });
            },
            error: function(e) {
               console.log(e.message);
            }
        });
    });
});

Upvotes: 1

Related Questions