Getting someone's Steam inventory

风格不统一 提交于 2019-11-26 23:46:06

New Endpoint

There is a new end point for fetching inventories as of December 2016. The old one listed below still works (for now). Both seem to be highly ratelimited.

The new inventory path is:

http://steamcommunity.com/inventory/<PROFILEID>/440/2?l=english&count=5000

With this new path, l is the language you want to receive data back in and count is the number of items to receive back at a time. The maximum is 5000.

You can paginate with this new end point too:

http://steamcommunity.com/inventory/<PROFILEID>/440/2?l=english&count=5000&start_assetid=468336866

This will pull the next 5000 items starting with assetid 468336866.

The end point returns a large json object with the following structure:

{ 
    'assets': <list>,
    'descriptions': <list>,
    'total_inventory_count': integer,
    'success': 1/0,
    'rwgran': integer
}

I am not completely sure what rwgran is at this point.

The assets key, returns data that looks like this:

[{'amount': '1',
         'appid': '440',
         'assetid': '4985815666',
         'classid': '134',
         'contextid': '2',
         'instanceid': '0'},
        {'amount': '1',
         'appid': '440',
         'assetid': '4985815941',
         'classid': '22989188',
         'contextid': '2',
         'instanceid': '0'},
        ...
]

The descriptions key contains entries like this. Notice that this contains a lot for information than the old end point.

[{'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'},
      ...
]

As with the old method, the assets and descriptions are linked via the classid in both.


Old Endpoint

You can get some limited information if the target has their profile permissions set appropriately.

You can view the resulting json files by using either of these two links for beta (and gift, if appropriate permissions are set) inventories

http://steamcommunity.com/id/<CUSTOMURL>/inventory/json/753/1 http://steamcommunity.com/profiles/<PROFILEID>/inventory/json/753/1

CUSTOMURL is the user friendly name the player has selected to use. This is changeable by the player at any time. If you are writing a web page, I assume you know how to get this piece of information, correct? PROFILEID is the 64Bit id that a player is given by Steam when you create the account. This is not changeable and it is returned by Steam when they log in using an OpenID implementation.

When using those URLs, there are a few possible responses. The first is if the user has their profile set to private.

{"success":false,"Error":"This profile is private."}

The second is a listing of "stuff" in the inventory

{
    "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"}
            ]
        }
    }
}

If the URL is for YOUR ID and you are logged into Steam, you can also see items that are listed as Gift. Otherwise, those are hidden by default.

Since this isn't an official API, there isn't much documentation about this particular schema. However, it appears that the items in rgInventory are linked to items in the reDescriptions by classid. Writing the parser is left as an exercise for the reader.

These shows the beta accesses.

If you are looking for trading card information, change the 1 in the above URLs to a 6

http://steamcommunity.com/id/<CUSTOMURL>/inventory/json/753/6 http://steamcommunity.com/profiles/<PROFILEID>/inventory/json/753/6

The schema layouts appear to be the same for these.

Just to precise Andy's answer, the schema is:

http://steamcommunity.com/profiles/<PROFILEID>/inventory/json/<APPID>/<CONTEXTID>

App ID identifies the game/application this inventory is related to : here's the list.

Context ID filters the items, it varies from game to game.

Another thing: the items returned are uniquely identified by the classid-instanceid pair (source), so when you link them with their description, you should take both into account.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!