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

I could see my Steam achievements in http://steamcommunity.com/id/userId How to display them in my website

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

如何在网站上显示我的 Steam 个人资料、仪表板、游戏统计数据和成就

本文档介绍了如何在您的网站上显示您的 Steam 个人资料、仪表板、游戏统计信息和成就。

示例:

中提供了一个实例

https://newtonjoshua.com

蒸汽:

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

参考:

http://store.steampowered.com

https://steamcommunity.com

https://www.facebook.com/Steam

Steam 网站 API:

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

参考:

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

Steam 网站 API 密钥:

所有对 Steam Web API 的使用都需要使用 API 密钥。您可以通过填写此表格获得一个。 https://steamcommunity.com/dev/apikey

String key = "{{apikey}}";

Steam ID:

使用您的 Steam 用户名获取您的 Steam ID。

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

需要 Steam 64 ID steam_id

String steamId = "{{steam_id}}";

接口和方法:

注意:您不能从(客户端)浏览器发送 API 请求。它会抛出“请求的资源上不存在 'Access-Control-Allow-Origin' header”。 因此,从您的服务器访问 Steam Web API。

此答案中给出了一个 JAVA 示例。

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

http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={{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 return是玩家拥有的游戏列表以及一些游戏时间信息。

http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key={{key}}&steamid={{steamId}}&include_appinfo=1&format=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);
    }

您需要该应用程序 ID 才能获取该 App/Game

的详细信息

GetUserStatsForGame: Returns 此用户的应用程序 ID 成就列表

http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?key={{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 returns 游戏名称、游戏版本和可用游戏状态(成就和统计数据)。

http://api.steampowered.com/ISteamUserStats/GetSchemaForGame/v0002/?key={{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);

return结果

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

    return result;

使用 userStats 映射 gameSchema

您可以将您的成就和统计数据映射到架构中,以获得您的成就的更多详细信息。 这将使在您的网站上显示的数据更具吸引力。

下面给出了将 userStats 映射到 gameSchema 的示例。

 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
                }
            });
        });
}