本文介绍了获取某人的 Steam 库存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个需要访问用户 Steam 库存的网站.我找到了一个 API 来获取军团要塞 2、Dota 2、CS:S、CS:GO 和 Portal 2.但我没有找到任何获取 Steam 库存的 API.

I am making a website that needs to access the Steam inventory of the user. I found an API to get Team Fortress 2 inventory, Dota 2, CS:S, CS:GO and Portal 2. But I didn't find any API for getting Steam inventory.

是否可以访问用户的 Steam 库存?

Is it possible to access a user's Steam inventory?

推荐答案

New Endpoint

截至 2016 年 12 月,有一个用于获取库存的新端点.下面列出的旧端点仍然有效(目前).两者似乎都受到高度限制.

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.

新的库存路径是:

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

使用这个新路径,l 是您想要接收回数据的语言,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

这将提取接下来的 5000 个以 assetid 468336866 开头的项目.

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

终点返回一个大的json对象,结构如下:

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
}

我现在不完全确定 rwgran 是什么.

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

assets 键,返回如下所示的数据:

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

descriptions 键包含这样的条目.请注意,这比旧的终点包含更多信息.

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

与旧方法一样,assetsdescriptions 通过两者中的 classid 链接.

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

如果目标的个人资料权限设置适当,您可以获得一些有限的信息.

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

您可以使用这两个链接中的任何一个来查看生成的 json 文件以获取测试版(和礼物,如果设置了适当的权限)库存

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//inventory/json/753/1http://steamcommunity.com/profiles//inventory/json/753/1

CUSTOMURL 是玩家选择使用的用户友好名称.这可以由玩家随时更改.如果您正在编写网页,我假设您知道如何获取此信息,对吗?PROFILEID 是玩家在创建帐户时由 Steam 提供的 64 位 ID.这是不可更改的,并且在 Steam 使用 OpenID 实现登录时返回.

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.

使用这些 URL 时,有几种可能的响应.第一个是用户是否将他们的个人资料设置为私人.

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":"此个人资料是私密的."}

第二个是清单中的东西"列表

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

如果 URL 是您的 ID 并且您已登录 Steam,您还可以看到列为 Gift 的物品.否则,这些默认情况下是隐藏的.

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.

由于这不是官方 API,因此没有太多关于此特定架构的文档.但是,rgInventory 中的项目似乎通过 classid 链接到 reDescriptions 中的项目.编写解析器留给读者作为练习.

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.

如果您要查找交易卡信息,请将上述 URL 中的 1 更改为 6

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

http://steamcommunity.com/id//inventory/json/753/6http://steamcommunity.com/profiles//inventory/json/753/6

架构布局似乎与这些相同.

The schema layouts appear to be the same for these.

这篇关于获取某人的 Steam 库存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 05:50