Skip to main content

Xbox-WebAPI-EX

Latest Version Code Coverage Build Status Documentation Status

Xbox-WebAPI is a python library to authenticate with Xbox Live via your Microsoft Account and provides Xbox related Web-API.

Authentication via credentials or tokens is supported, Two-Factor-Authentication ( 2FA ) is also possible.

Dependencies

  • Python >= 3.5

  • Libraries: requests, demjson, appdirs, urwid

How to use

Install:

pip install xbox-webapi-ex

Authentication:

# Token save location: If tokenfile is not provided via cmdline, fallback
# of <appdirs.user_data_dir>/tokens.json is used as save-location
#
# Specifically:
# Windows: C:\\Users\\<username>\\AppData\\Local\\OpenXbox\\xbox
# Mac OSX: /Users/<username>/Library/Application Support/xbox/tokens.json
# Linux: /home/<username>/.local/share/xbox
#
# For more information, see: https://pypi.org/project/appdirs and module: xbox.webapi.scripts.constants

xbox-authenticate --tokens tokens.json --email no@live.com --password abc123

# NOTE: If no credentials are provided via cmdline, they are requested from stdin
xbox-authenticate --tokens tokens.json

# If you have a shell compatible with ncurses, you can use the Terminal UI app
xbox-auth-ui --tokens tokens.json

Fallback Authentication:

# In case this authentication flow breaks or you do not trust the code with your credentials..
# Open the following URL in your web-browser and authenticate
https://login.live.com/oauth20_authorize.srf?display=touch&scope=service%3A%3Auser.auth.xboxlive.com%3A%3AMBI_SSL&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf&locale=en&response_type=token&client_id=0000000048093EE3

# Once you finished auth and reached a blank page, copy the redirect url from your browser address-field
# Execute the script with supplied redirect url
xbox-auth-via-browser 'https://login.live.com/oauth20_desktop.srf?...access_token=...&refresh_token=...'

Example: Search Xbox Live via cmdline tool:

# Search Xbox One Catalog
xbox-searchlive --tokens tokens.json "Some game title"

# Search Xbox 360 Catalog
xbox-searchlive --tokens tokens.json -l "Some game title"

API usage:

import sys

from xbox.webapi.api.client import XboxLiveClient
from xbox.webapi.authentication.manager import AuthenticationManager
from xbox.webapi.common.exceptions import AuthenticationException

"""
For doing authentication in code, see xbox/webapi/scripts/authenticate.py
or for OAUTH via web-brower, see xbox/webapi/scripts/browserauth.py
"""

try:
  auth_mgr = AuthenticationManager.from_file('/path_to/tokens.json')
except FileNotFoundError as e:
  print(
    'Failed to load tokens from \'{}\'.\n'
    'ERROR: {}'.format(e.filename, e.strerror)
  )
  sys.exit(-1)

try:
  auth_mgr.authenticate(do_refresh=True)
except AuthenticationException as e:
  print('Authentication failed! Err: %s' % e)
  sys.exit(-1)

xbl_client = XboxLiveClient(auth_mgr.userinfo.userhash, auth_mgr.xsts_token.jwt, auth_mgr.userinfo.xuid)

# Some example API calls

# Get friendslist
friendslist = xbl_client.people.get_friends_own()

# Get presence status (by list of XUID)
presence = xbl_client.presence.get_presence_batch([12344567687845, 453486346235151])

# Get messages
messages = xbl_client.message.get_message_inbox()

# Get profile by GT
profile = xbl_client.profile.get_profile_by_gamertag('SomeGamertag')

Screenshots

Here you can see the Auth TUI (Text user interface):

https://raw.githubusercontent.com/OpenXbox/xbox-webapi-python/master/assets/xbox_auth_tui_main.png https://raw.githubusercontent.com/OpenXbox/xbox-webapi-python/master/assets/xbox_auth_tui_2fa.png

Known issues

  • There are a lot of missing XBL endpoints

Contribute

  • Report bugs/suggest features

  • Add/update docs

  • Add additional xbox live endpoints

Credits

This package uses parts of Cookiecutter and the audreyr/cookiecutter-pypackage project template. The authentication code is based on joealcorn/xbox

Informations on endpoints gathered from:

Disclaimer

Xbox, Xbox One, Smartglass and Xbox Live are trademarks of Microsoft Corporation. Team OpenXbox is in no way endorsed by or affiliated with Microsoft Corporation, or any associated subsidiaries, logos or trademarks.

History

1.1.7 (2018-11-10)

  • Fix parsing of WindowsLive auth response

1.1.6 (2018-09-30)

  • Consider (User-)privileges of (XSTS) userinfo optional

  • Fix: Always return bool for @Property AuthenticationManager.authenticated

1.1.5 (2018-08-11)

  • Make property authenticated in AuthenticationManager check token validity

  • Break out of windows live auth early if cookies were cached previously

1.1.4 (2018-07-01)

  • Implement convenience functions for Partner Service Authentication

1.1.3 (2018-06-16)

  • Gracefully fail on wrong account password

  • Fix “ValueError: tui: Unexpected button pressed: Cancel”

  • provider.lists: Correct headers, GET list works

  • Titlehub: Support getting title history by xuid

1.1.2 (2018-05-06)

  • Fixing appdir (aka. token save location) creation on windows

1.1.1 (2018-05-03)

  • Removed python-dateutil dependency

  • Add auth-via-browser fallback script

  • Small changes

1.1.0 (2018-04-17)

  • Auth: Updated 2FA authentication to meet current windows live auth flow

  • Auth: Redesigned 2FA authentication procedure

  • Auth: Implemented xbox-auth-ui script (xbox.webapi.scripts.tui: urwid terminal ui)

  • Auth: For password masking, getpass instead or raw input() is used

  • Scripts: Default to appdirs.user_data_dir if no tokenfile provided via cmdline argument (see README)

1.0.9 (2018-03-30)

  • Extend Gameclips provider with title id filtering and saved clips

  • Add Screenshots provider

  • Add Titlehub provider

1.0.8 (2018-03-29)

  • Added Userstats endpoint

  • Updated README

1.0.7 (2018-03-28)

  • Support supplying auth credentials via stdin

  • Added tests for all endpoints

  • Added tests for authentication

  • Added QCS endpoint

  • Added Profile endpoint

  • Added Achievements endpoint

  • Added Usersearch endpoint

  • Added Gameclips endpoint

  • Added People endpoint

  • Added Presence endpoint

  • Added Message endpoint

  • Removed Gamerpics endpoint

1.0.3 - 1.0.6 (2018-03-17)

  • Metadata changes

1.0.2 (2018-03-17)

  • More metadata changes, rendering on PyPi is fine now

1.0.1 (2018-03-17)

  • Metadata changes

1.0.0 (2018-03-17)

  • First release on PyPI.

Release files for xbox-webapi-ex 1.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xbox-webapi-ex 1.1.9
File Size Uploaded
xbox-webapi-ex-1.1.9.tar.gz 405.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xbox-webapi-ex 1.1.9
File Interpreter ABI Platform
xbox_webapi_ex-1.1.9-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 454.1 kB

Release files / xbox-webapi-ex-1.1.9.tar.gz

Download URL xbox-webapi-ex-1.1.9.tar.gz
Size 405.9 kB
Tags Source
SHA-256 checksum
How to use checksums
10c0097f8e42c49ec8b94c23b81167cd4d05ec3e228f5a610e40d45ce69ee1a4
BLAKE2b-256 checksum
How to use checksums
15adac1210ca646e8943499d68d5f9878e92412c101cc1e7595de2e7719699a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

Release files / xbox_webapi_ex-1.1.9-py2.py3-none-any.whl

Download URL xbox_webapi_ex-1.1.9-py2.py3-none-any.whl
Size 48.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
8d5f2989eae343de4fceef5b8654ce8a85213ddb1b753749572f6cf002830b3d
BLAKE2b-256 checksum
How to use checksums
99472a34271e511139efc838cfc81a5f651844ff8bbdb2170448d7300c6fc4cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

1.1.9 This release

2 release files

1.1.8

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page