我可以在http://steamcommunity.com/id/userId中看到我的Steam成就如何在我的网站上显示它们

时间:2017-07-13 14:11:38

标签: steam steam-web-api

如何在您的网站上显示您的蒸汽仪表板?

如何在网站上显示我的蒸汽档案,仪表板,游戏统计数据和成就

1 个答案:

答案 0 :(得分:0)

本文档介绍了如何在您的网站上显示您的简介,仪表板,游戏统计数据和成就。

示例:

中提供了一个实例
  

https://newtonjoshua.com

Steam:

Steam是Valve Corporation开发的数字分销平台,提供数字版权管理(DRM),多人游戏和社交网络服务。 Steam为用户提供多台计算机上的游戏安装和自动更新,以及社区功能,如朋友列表和群组,云端保存以及游戏内语音和聊天功能。 它有超过3,500场比赛。无论您使用的是PC,Mac,Linux机器,移动设备,还是电视,您都可以享受Steam带来的好处。 从Steampowered.com下载并运行Steam安装程序 你可以开始购买,下载并最终在其中玩游戏。

参阅:

  

http://store.steampowered.com

     

https://steamcommunity.com

     

https://www.facebook.com/Steam

Steam Web API:

Steam Web API是一组数据服务,用于获取与Valve Software的Steam平台相关的信息。 Valve提供这些API,因此网站开发人员可以以新的有趣方式使用Steam提供的数据。它们允许开发人员向Steam查询他们可以在自己的站点上显示的信息。

参阅:

  

https://developer.valvesoftware.com/wiki/Steam_Web_API

Steam Web API密钥:

所有使用Steam Web API都需要使用API​​密钥。您可以填写此表单获取一个。 https://steamcommunity.com/dev/apikey

String key = "{{apikey}}";

Steam ID:

使用您的蒸汽用户名来获取您的蒸汽ID。

  

http://steamid.co/player.php?input= {{的User_Name}}

Steam 64 ID是必需的steam_id

String steamId = "{{steam_id}}";

接口和方法:

注意:您无法从(客户端)浏览器发送API请求。它会抛出'No'Access-Control-Allow-Origin'标头出现在请求的资源上。 因此,请从您的服务器访问Steam Web API。

在这个答案中给出了一个JAVA例子。

GetPlayerSummaries: 返回64位Steam ID列表的基本配置文件信息。

  

http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key= {{键}}&安培; steamids = {{steamId}}

 //      Get Player Details           
    JSONObject playerSummary = HttpGet.get("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" + key + "&steamids=" + steamId);
    response = playerSummary.getJSONObject("response");
    JSONArray players = response.getJSONArray("players");
    player = players.getJSONObject(0);
    JSONObject result = new JSONObject();
    result.put("player", player);

GetOwnedGames: GetOwnedGames返回玩家拥有的游戏列表以及一些游戏时间信息。

  

http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key= {{键}}&安培; steamid = {{steamId}}&安培; include_appinfo = 1&安培;格式= JSON

//      Get all the Owned Games
    JSONObject ownedGames = HttpGet.get("http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=" + key + "&steamid=" + steamId + "&include_appinfo=1&format=json&include_played_free_games=1");
    JSONObject response = ownedGames.getJSONObject("response");
    JSONArray games = response.getJSONArray("games");

获取所有游戏的详细信息:

//      Loop through response.games[]
    for (int i = 0; i < games.length(); i++) {
        JSONObject game = games.getJSONObject(i);
        JSONObject gameData = new JSONObject();

        //          Copy the data in 'game' to 'gameData' and use 'game' for iteration
        gameData = game;

        String appid = game.getString("appid");

        // userStats : get stats and achievements of the user for the app

        // gameSchema :  get schema of the app

        gameData = getGameData(userStats, gameSchema, gameData);
        gameFeeds.put(gameData);
    }

您将需要appid来获取该应用程序/游戏的详细信息

GetUserStatsForGame: 按应用ID返回此用户的成就列表

  

http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?key= {{键}}&安培; steamid = {{steamId}}&安培;的appid = {{APPID}}

这将列出您在游戏中的成就和统计数据

// Get UserStats (Achievements and Statistics) For game
JSONObject userStats =
    HttpGet.get("http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?key=" + key + "&steamid=" + steamId + "&appid=" + appid);

GetSchemaForGame: GetSchemaForGame返回gamename,gameversion和availablegamestats(成就和统计数据)。

  

http://api.steampowered.com/ISteamUserStats/GetSchemaForGame/v0002/?key= {{键}}&安培; steamid = {{steamId}}&安培;的appid = {{APPID}}

这将提供所有成就和统计的完整细节。

//          Get Schema For game to get more details about the achievements and statistics of the user
JSONObject gameSchema =
    HttpGet.get("http://api.steampowered.com/ISteamUserStats/GetSchemaForGame/v0002/?key=" + key + "&steamid=" + steamId + "&appid=" + appid);

返回结果

//          set gameFeeds[] to result.games
    result.put("games", gameFeeds);

    return result;

使用userStats映射gameSchema

您可以使用架构映射您的成就和统计数据,以获取有关ypur成就的更多详细信息。 这将为您的网站提供更具吸引力的数据。

下面给出了使用gameSchema映射userStats的示例。

 public static JSONObject getGameData(JSONObject userStats, JSONObject gameSchema, JSONObject gameData) throws JSONException {

    //          Set the playerStats and gameSchema
    if (userStats.has("playerstats")) {
        userStats = userStats.getJSONObject("playerstats");

        if (gameSchema.has("game")) {
            gameSchema = gameSchema.getJSONObject("game");

            if (gameSchema.has("availableGameStats")) {
                JSONObject availableGameStats = gameSchema.getJSONObject("availableGameStats");

                // Achievements
                if (userStats.has("achievements") && availableGameStats.has("achievements")) {
                    JSONArray achievements = userStats.getJSONArray("achievements");
                    JSONArray resAchievements = new JSONArray();
                    JSONArray reference = availableGameStats.getJSONArray("achievements");

                    //                          Iterate though achievements from playerstats.achievements[] obtained from GetUserStatsForGame
                    for (int j = 0; j < achievements.length(); j++) {
                        JSONObject achievement = achievements.getJSONObject(j);
                        String name = achievement.getString("name");

                        //                              Iterate through reference game.availableGameStats.achievements[] obtained from GetSchemaForGame
                        for (int k = 0; k < reference.length(); k++) {
                            JSONObject ref = reference.getJSONObject(k);
                            String refName = ref.getString("name");

                            if (name.equals(refName)) {

                                //                                      put all the data from Schema for all the Achievements of the user in resAchievements
                                resAchievements.put(ref);

                                break;
                            }
                        }
                    }

                    //                          put resAchievements in gameData.achievements
                    gameData.put("achievements", resAchievements);
                }

                // Stats
                if (userStats.has("stats") && availableGameStats.has("stats")) {
                    JSONArray stats = userStats.getJSONArray("stats");
                    JSONArray resStats = new JSONArray();
                    JSONArray reference = availableGameStats.getJSONArray("stats");

                    //                          Iterate though stats from playerstats.stats[] obtained from GetUserStatsForGame
                    for (int j = 0; j < stats.length(); j++) {
                        JSONObject stat = stats.getJSONObject(j);
                        String name = stat.getString("name");
                        int value = stat.getInt("value");

                        //                              Iterate through reference game.availableGameStats.stats[] obtained from GetSchemaForGame
                        for (int k = 0; k < reference.length(); k++) {
                            JSONObject ref = reference.getJSONObject(k);
                            String refName = ref.getString("name");

                            if (name.equals(refName)) {

                                //                                      put all the data from Schema for all the stats of the user in resStats
                                ref.put("value", value);
                                resStats.put(ref);

                                break;
                            }
                        }
                    }

                    //                          put resStats in gameData.stats
                    gameData.put("stats", resStats);
                }
            }
        }
    }

    return gameData;
}

注意:上面的JAVA示例未针对更好的性能进行调整。由于Steam API请求是在单个线程中发送的,因此大量游戏可能会延迟响应。尝试多线程方法发送请求。

显示数据:

从服务器API获取结果并在您的网站中显示数据。

'use strict';

function getSteamFeeds() {
    $.get('{{api URI}}',
        function (feeds) {
            var avatar = feeds.player.avatarfull;
            var profile = feeds.player.profileurl;

    // Iterate through each game.
            feeds.games.forEach(function (game) {
        // Get game data
        var gameName = game.name;
                var gameIcon = 'http://media.steampowered.com/steamcommunity/public/images/apps/' + game.appid + '/' + game.img_icon_url + '.jpg';
                var gameLogo = 'http://media.steampowered.com/steamcommunity/public/images/apps/' + game.appid + '/' + game.img_logo_url + '.jpg';
                var gamePlayTime = Math.ceil(game.playtime_forever / 60);
                var gameLink = 'http://store.steampowered.com/app/' + game.appid;

                if (game.achievements) {
                    game.achievements.forEach(function (achievement) {
            var achievementIcon = achievement.icon;
            var achievementDisplayName = achievement.displayName;
            var achievementLink = 'http://steamcommunity.com/id/NewtonJoshua/stats/' + game.appid;
            var achievementDescription = achievement.description;
                        // display the achievements for thegame
                    });
                }
        if (game.stats) {
            var statDisplayName = stat.displayName;
            var statValue = stat.value;
            // use google.visualization.Table to display the data
                }
            });
        });
}