【发布时间】:2013-06-27 21:40:13
【问题描述】:
我正在制作一个需要访问用户 Steam 库存的网站。我找到了获取 Team Fortress 2 库存、Dota 2、CS:S、CS:GO 和 Portal 2 的 API。但我没有找到任何获取 Steam 库存的 API。
是否可以访问用户的 Steam 库存?
【问题讨论】:
我正在制作一个需要访问用户 Steam 库存的网站。我找到了获取 Team Fortress 2 库存、Dota 2、CS:S、CS:GO 和 Portal 2 的 API。但我没有找到任何获取 Steam 库存的 API。
是否可以访问用户的 Steam 库存?
【问题讨论】:
自 2016 年 12 月起,有一个用于获取库存的新端点。下面列出的旧端点仍然有效(目前)。两者似乎都受到高度限制。
新的库存路径是:
http://steamcommunity.com/inventory/<PROFILEID>/440/2?l=english&count=5000
使用这条新路径,l 是您想要接收回数据的语言,count 是一次接收回的项目数。最大值为 5000。
您也可以使用这个新的端点进行分页:
http://steamcommunity.com/inventory/<PROFILEID>/440/2?l=english&count=5000&start_assetid=468336866
这将提取以assetid 468336866 开头的接下来的 5000 个项目。
端点返回一个大的json对象,结构如下:
{
'assets': <list>,
'descriptions': <list>,
'total_inventory_count': integer,
'success': 1/0,
'rwgran': integer
}
我现在不完全确定rwgran 是什么。
assets 键返回如下所示的数据:
[{'amount': '1',
'appid': '440',
'assetid': '4985815666',
'classid': '134',
'contextid': '2',
'instanceid': '0'},
{'amount': '1',
'appid': '440',
'assetid': '4985815941',
'classid': '22989188',
'contextid': '2',
'instanceid': '0'},
...
]
descriptions 键包含这样的条目。请注意,这包含比旧端点更多的信息。
[{'actions': [{'link': 'http:\\/\\/wiki.teamfortress.com\\/scripts\\/itemredirect.php?id=241&lang=en_US',
'name': 'Item Wiki Page...'}],
'appid': 440,
'background_color': '3C352E',
'classid': '134',
'commodity': 0,
'currency': 0,
'descriptions': [{'type': 'text',
'value': 'Is an enemy player questioning your skills, personal hygiene, and\\/or ancestry?\nUse these stylish firearms to challenge them to a duel!\nSee the Mann Co. Catalog for full details.'},
{'type': 'text', 'value': ' '},
{'color': '00a000',
'type': 'text',
'value': 'This is a limited use item. Uses: 5'}],
'icon_url': 'fWFc82js0fmoRAP-qOIPu5THSWqfSmTELLqcUywGkijVjZULUrsm1j-9xgECbwgfYh_3vTRKhs_ZAfOeD-VOyo4z4clTizJqwQcpYOHnNDFmcweRVqQPCqVq91C-WCM26pFnB4PjofUWJ1uAGDnHsA',
'icon_url_large': 'fWFc82js0fmoRAP-qOIPu5THSWqfSmTELLqcUywGkijVjZULUrsm1j-9xgECbwgfYh_3vTRKhs_ZAfOeD-VOyo4z4clTizJqwQcpYOHnNDFmcweRVqQPCqVq91C-WCM26pFnB4PjofUWJ1uAGDnHsA',
'instanceid': '0',
'market_hash_name': 'Dueling Mini-Game',
'market_marketable_restriction': 0,
'market_name': 'Dueling Mini-Game',
'market_tradable_restriction': 7,
'marketable': 0,
'name': 'Dueling Mini-Game',
'name_color': '7D6D00',
'tags': [{'category': 'Quality',
'color': '7D6D00',
'internal_name': 'Unique',
'localized_category_name': 'Quality',
'localized_tag_name': 'Unique'},
{'category': 'Type',
'internal_name': 'TF_UsableItem',
'localized_category_name': 'Type',
'localized_tag_name': 'Usable Item'},
{'category': 'Class',
'internal_name': 'Scout',
'localized_category_name': 'Class',
'localized_tag_name': 'Scout'},
{'category': 'Class',
'internal_name': 'Sniper',
'localized_category_name': 'Class',
'localized_tag_name': 'Sniper'},
{'category': 'Class',
'internal_name': 'Soldier',
'localized_category_name': 'Class',
'localized_tag_name': 'Soldier'},
{'category': 'Class',
'internal_name': 'Demoman',
'localized_category_name': 'Class',
'localized_tag_name': 'Demoman'},
{'category': 'Class',
'internal_name': 'Medic',
'localized_category_name': 'Class',
'localized_tag_name': 'Medic'},
{'category': 'Class',
'internal_name': 'Heavy',
'localized_category_name': 'Class',
'localized_tag_name': 'Heavy'},
{'category': 'Class',
'internal_name': 'Pyro',
'localized_category_name': 'Class',
'localized_tag_name': 'Pyro'},
{'category': 'Class',
'internal_name': 'Spy',
'localized_category_name': 'Class',
'localized_tag_name': 'Spy'},
{'category': 'Class',
'internal_name': 'Engineer',
'localized_category_name': 'Class',
'localized_tag_name': 'Engineer'}],
'tradable': 1,
'type': 'Level 5 Usable Item'},
...
]
与旧方法一样,assets 和 descriptions 都通过 classid 链接。
如果目标的个人资料权限设置得当,您可以获得一些有限的信息。
您可以使用这两个链接中的任何一个链接查看生成的 json 文件以获取测试版(和礼物,如果设置了适当的权限)库存
http://steamcommunity.com/id/<CUSTOMURL>/inventory/json/753/1
http://steamcommunity.com/profiles/<PROFILEID>/inventory/json/753/1
CUSTOMURL 是玩家选择使用的用户友好名称。这可由玩家随时更改。如果您正在编写网页,我假设您知道如何获取这些信息,对吗? PROFILEID 是 Steam 在您创建帐户时为玩家提供的 64 位 ID。这是不可更改的,它会在 Steam 使用 OpenID 实现登录时返回。
使用这些 URL 时,有几种可能的响应。第一个是用户是否将他们的个人资料设置为私人。
{"success":false,"Error":"This profile is private."}
第二个是清单中“东西”的列表
{
"success":true,
"rgInventory":
{
"1586670077416875609":
{
"id":"1586670077416875609",
"classid":"149742033",
"instanceid":"0",
"amount":"1",
"pos":1
},
"1586670077416875905":
{
"id":"1586670077416875905",
"classid":"149742033",
"instanceid":"0",
"amount":"1",
"pos":2
},
"1586670077416877092":
{
"id":"1586670077416877092",
"classid":"149742033",
"instanceid":"0",
"amount":"1",
"pos":3
}
},
"rgCurrency":[],
"rgDescriptions":
{
"149742033_0":
{ "appid":"753",
"classid":"149742033",
"instanceid":"0",
"icon_url":"ZyjGwQD4ogROtSm7KvtdP99kDHBEiKxKm3Gg7pMaBJyiPu4iS_PzF6QhOUdOwk-m0WhXYQ7X8AbNL6Hz1VxOnq4-8iBC5MlBuXMuElaaCrHQLww9T5S1Ecoqo_PYWg==",
"icon_url_large":"a6FEz5nbBlvu8bGd1oDggdPtjn7dqwgVOzU4yG9huSKut2ws0tBXSARloWGyufIY3eHVb5f0VFltaznVKSfzK6amZz7FjFhcTTm6Maz860eOrMo937A=",
"icon_drag_url":"",
"name":"Steam Trading Card Beta",
"market_name":"",
"name_color":"",
"background_color":"",
"type":"Gift",
"tradable":1,
"marketable":0,
"descriptions":[
{"value":"Steam Trading Card Beta Access - Extra Copy"},
{"value":"Grants early access to the Steam Trading Cards beta, game badges, and the new profile. Join the Steam Trading Cards Group and post your feedback in the Discussions area. Select \u201cAdd to my game library\u201d to activate."}
],
"actions":[
{"name":"View in store","link":"http:\/\/steamcommunity.com\/tradingcards"}
]
}
}
}
如果 URL 是您的 ID 并且您已登录 Steam,您还可以看到列为 Gift 的项目。否则默认隐藏。
由于这不是官方 API,因此没有太多关于此特定架构的文档。但是,rgInventory 中的项目似乎通过classid 链接到reDescriptions 中的项目。编写解析器留给读者作为练习。
这些显示测试访问。
如果您正在寻找交易卡信息,请将上述 URL 中的 1 更改为 6
http://steamcommunity.com/id/<CUSTOMURL>/inventory/json/753/6
http://steamcommunity.com/profiles/<PROFILEID>/inventory/json/753/6
这些架构布局似乎相同。
【讨论】:
?start=#### 以检索下一组项目。例如?start=2500。这对于获取大量库存的完整数据是必要的。
/2 (http://steamcommunity.com/id/<CUSTOM_URL>/inventory/json/730/2/) 给了你他们普通的库存内容。
为了准确的安迪的回答,架构是:
http://steamcommunity.com/profiles/<PROFILEID>/inventory/json/<APPID>/<CONTEXTID>
App ID 标识了与此库存相关的游戏/应用程序:here's the list。
上下文 ID 过滤项目,它因游戏而异。
另一件事:返回的项目由 classid-instanceid 对 (source) 唯一标识,因此当您将它们与其描述相关联时,您应该将两者都考虑在内。
【讨论】:
g_rgAppContextData 的全局变量注入到列出可用上下文的页面正文中。