Browse Source

fix #269; get_product_info() fail for packages requiring access_token

Valve introduced access_tokens to packages that can be found in liceneses
pull/287/head
Rossen Georgiev 5 years ago
parent
commit
03705d03c6
  1. 31
      steam/client/builtins/apps.py
  2. 3
      steam/client/cdn.py

31
steam/client/builtins/apps.py

@ -7,7 +7,7 @@ from steam.utils.proto import proto_fill_from_dict
class Apps(object): class Apps(object):
licenses = None #: :class:`dict` Account licenses licenses = None #: :class:`dict` Accounts' package licenses
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(Apps, self).__init__(*args, **kwargs) super(Apps, self).__init__(*args, **kwargs)
@ -57,9 +57,12 @@ class Apps(object):
'packages': {123: {...}, ...} 'packages': {123: {...}, ...}
} }
When a token is needed to access the full info (e.g. branches and depots) the ``_missing_token`` Access token is needed to access full information for certain apps, and also package info.
will be set to ``True``. The token can be obtained by calling :meth:`get_access_tokens` if Each app and package has its' own access token.
the account has a license. If a token is required then ``_missing_token=True`` in the response.
App access tokens are obtained by calling :meth:`get_access_tokens`, and are returned only
when the account has a license for the specified app. Example code:
.. code:: python .. code:: python
@ -68,9 +71,21 @@ class Apps(object):
if result['apps'][123]['_missing_token']: if result['apps'][123]['_missing_token']:
tokens = client.get_access_token(apps=[123]) tokens = client.get_access_token(apps=[123])
result = client.get_product_info(apps={'appid': 123, result = client.get_product_info(apps=[{'appid': 123,
'access_token': tokens['apps'][123] 'access_token': tokens['apps'][123]
}) }])
.. note::
It is best to just request access token for all apps, before sending a product info
request.
Package tokens are located in the account license list. See :attr:`.licenses`
.. code:: python
result = client.get_product_info(packages=[{'packageid': 123,
'access_token': client.licenses[123].access_token,
}])
""" """
if not apps and not packages: if not apps and not packages:
return return
@ -107,7 +122,7 @@ class Apps(object):
data['apps'][app.appid] = vdf.loads(app.buffer[:-1].decode('utf-8', 'replace'))['appinfo'] data['apps'][app.appid] = vdf.loads(app.buffer[:-1].decode('utf-8', 'replace'))['appinfo']
data['apps'][app.appid]['_missing_token'] = app.missing_token data['apps'][app.appid]['_missing_token'] = app.missing_token
for pkg in chunk.packages: for pkg in chunk.packages:
data['packages'][pkg.packageid] = vdf.binary_loads(pkg.buffer[4:])[str(pkg.packageid)] data['packages'][pkg.packageid] = vdf.binary_loads(pkg.buffer[4:]).get(str(pkg.packageid), {})
data['packages'][pkg.packageid]['_missing_token'] = pkg.missing_token data['packages'][pkg.packageid]['_missing_token'] = pkg.missing_token
if not chunk.response_pending: if not chunk.response_pending:

3
steam/client/cdn.py

@ -478,7 +478,8 @@ class CDNClient(object):
self._LOG.debug("No steam licenses found on SteamClient instance") self._LOG.debug("No steam licenses found on SteamClient instance")
return return
packages = list(self.steam.licenses.keys()) packages = list(map(lambda l: {'packageid': l.package_id, 'access_token': l.access_token},
itervalues(self.steam.licenses)))
for package_id, info in iteritems(self.steam.get_product_info(packages=packages)['packages']): for package_id, info in iteritems(self.steam.get_product_info(packages=packages)['packages']):
self.licensed_app_ids.update(info['appids'].values()) self.licensed_app_ids.update(info['appids'].values())

Loading…
Cancel
Save