我正在制作一个需要访问用户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
进行关联。
在某些地区(取决于帐户区域),此终端点将返回{"success":false,"Error":"不支持的请求"}
。预计所有地区都将在不久的将来关闭此终端点。
如果目标设置了其个人资料权限,则可以获取一些有限信息。
您可以使用以下两个链接之一查看beta(和gift,如果设置了适当的权限)清单的json
文件:
http://steamcommunity.com/id/<CUSTOMURL>/inventory/json/753/1
http://steamcommunity.com/profiles/<PROFILEID>/inventory/json/753/1
CUSTOMURL
是玩家选择使用的用户友好名称。这可以随时由玩家更改。如果您正在编写网页,则我假设您知道如何获取此信息,对吗? PROFILEID
是Steam在使用OpenID实现登录时授予玩家的64位ID。这是不可更改的,并且在玩家登录时由Steam返回。
当使用这些URL时,有几种可能的响应。第一种是如果用户将其资料设置为私人。
{"success":false,"Error":"此个人资料已设为私人。"}
第二个是库存中的“内容”列表
{
"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”的物品。否则,这些物品默认是隐藏的。
?start=####
来获取下一批库存。例如?start=2500
。这是为了获取非常大的库存的完整数据而必需的。 - Chrisuu/2
(http://steamcommunity.com/id/<CUSTOM_URL>/inventory/json/730/2/
) 给出了他们的普通库存内容。 - Jeremy