使用SteamApi来获取Steam近期的游戏时长
前言
为了在自己博客里加一个近况列表,所以去简单了解了一下 Steam 官方的接口文档,这里将会分享其中几个常用接口。
介绍
Steam Web API 是由 Valve 官方提供的一个服务接口,可以用来获取 Steam 的游戏数据。
官方文档: https://developer.valvesoftware.com/wiki/Steam_Web_API
接口使用条款及说明: https://steamcommunity.com/dev/apiterms
准备
想要获取自己的数据首先我们需要准备以下两个东西
1.Steam Web API Token
Token申请: https://steamcommunity.com/dev/apikey
网页端Steam访问不了个人资料的话,可以尝试挂加速,或者使用羽翼城大佬写的steamcommunity 302工具
然后填写上域名并且勾选 ☑️ I agree…,然后点击注册即可获得我们所需要的密钥
2.Steam Id
自己账户的 Steam Id 可以在 Steam 的网页端中获取到
在网页端右上角账户名位置 点击查看个人资料
然后在地址栏中就可以拿到我们账户的 Steam Id 了
获取
获取近期玩过的游戏(2周内)
接口地址示例:
http://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v1?key={你的ApiToken}&steamid={你的SteamId}
请求方式:
GET
请求参数:
参数名 描述 必填 key 你的WebApiToken 是 steamid 你的SteamId 是 count 需要返回的游戏数量(一般不需要设置) 否 format 返回消息体的类型 json(默认)\ xml \ vdf 否 返回消息体示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17{
"response": {
"total_count": 1,
"games": [
{
"appid": 1418630,
"name": "Dread Hunger",
"playtime_2weeks": 113,
"playtime_forever": 425,
"img_icon_url": "8208301d8aeaa4804e8a8c6786c0780c83590cfa",
"playtime_windows_forever": 425,
"playtime_mac_forever": 0,
"playtime_linux_forever": 0
}
]
}
}返回体参数:
参数名 描述 total_count 返回的游戏总数 games 游戏列表 appid 游戏的唯一标识 name 游戏名 playtime_2weeks 近两周游玩时长(分钟) playtime_forever 游玩总时长(分钟) img_icon_url 游戏缩略图的文件名 playtime_windows_forever Windows上游玩总时长(分钟) playtime_mac_forever Mac上游玩总时长(分钟) playtime_linux_forever Linux上游玩总时长(分钟) 获取游戏缩略图
通过刚才的接口,我们已经可以拿到对应游戏
appid
以及游戏的img_icon_url
然后我们可以通过访问如下地址拿到对应游戏的缩略图
http://media.steampowered.com/steamcommunity/public/images/apps/{appid}/{img_icon_url}.jpg
这样的话我们就可以直接用在img标签的src里了
例:
1
<img src="http://media.steampowered.com/steamcommunity/public/images/apps/{appid}/{img_icon_url}.jpg"/>
其他常用接口
GetOwnedGames 获取已拥有的游戏列表
接口地址示例:
http://api.steampowered.com/IPlayerService/GetOwnedGames/v1?key={你的ApiToken}&steamid={你的SteamId}&include_appinfo=1
请求方式:
GET
请求参数:
参数名 描述 必填 key 你的WebApiToken 是 steamid 你的SteamId 是 include_appinfo 是否需要包含游戏详情(游戏名、缩略图等) 默认0 否 include_played_free_games 是否需要包含免费游戏 默认0 否 format 返回消息体的类型 json(默认)\ xml \ vdf 否 appids_filter 指定返回一组游戏,可传入多个游戏appid (例:”input_json={appids_filter: [440, 500]}”)📌传参规则 否 返回消息体示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17{
"response": {
"game_count": 1,
"games": [
{
"appid": 4000,
"name": "Garry's Mod",
"playtime_forever": 1284,
"img_icon_url": "4a6f25cfa2426445d0d9d6e233408de4d371ce8b",
"has_community_visible_stats": true,
"playtime_windows_forever": 0,
"playtime_mac_forever": 0,
"playtime_linux_forever": 0
}
]
}
}返回体参数:
参数名 描述 total_count 返回的游戏总数 games 游戏列表 appid 游戏的唯一标识 name 游戏名 playtime_forever 游玩总时长(分钟) img_icon_url 游戏缩略图的文件名 has_community_visible_stats 表示该游戏有成就统计页面(没什么用) playtime_windows_forever Windows上游玩总时长(分钟) playtime_mac_forever Mac上游玩总时长(分钟) playtime_linux_forever Linux上游玩总时长(分钟)