1- import sys
21import asyncio
3- from httpx import AsyncClient , HTTPStatusError
2+ import sys
3+
4+ from httpx import HTTPStatusError
5+
46from xbox .webapi .api .client import XboxLiveClient
57from xbox .webapi .authentication .manager import AuthenticationManager
68from xbox .webapi .authentication .models import OAuth2TokenResponse
9+ from xbox .webapi .common .signed_session import SignedSession
710from xbox .webapi .scripts import CLIENT_ID , CLIENT_SECRET , TOKENS_FILE
811
912# This uses the default client identification by OpenXbox
1518"""
1619For doing authentication, see xbox/webapi/scripts/authenticate.py
1720"""
21+
22+
1823async def async_main ():
19- async with AsyncClient () as session :
20- auth_mgr = AuthenticationManager (
21- session , client_id , client_secret , ""
22- )
24+ async with SignedSession () as session :
25+ auth_mgr = AuthenticationManager (session , client_id , client_secret , "" )
2326
2427 try :
25- with open (tokens_file , mode = "r" ) as f :
26- tokens = f .read ()
28+ with open (tokens_file ) as f :
29+ tokens = f .read ()
2730 auth_mgr .oauth = OAuth2TokenResponse .parse_raw (tokens )
2831 except FileNotFoundError :
29- print (f' File { tokens_file } isn`t found or it doesn`t contain tokens!' )
32+ print (f" File { tokens_file } isn`t found or it doesn`t contain tokens!" )
3033 exit (- 1 )
31-
34+
3235 try :
33- await auth_mgr .refresh_tokens ()
36+ await auth_mgr .refresh_tokens ()
3437 except HTTPStatusError :
35- print ("Could not refresh tokens" )
36- sys .exit (- 1 )
38+ print ("Could not refresh tokens" )
39+ sys .exit (- 1 )
3740
3841 with open (tokens_file , mode = "w" ) as f :
39- f .write (auth_mgr .oauth .json ())
40- print (f' Refreshed tokens in { tokens_file } !' )
42+ f .write (auth_mgr .oauth .json ())
43+ print (f" Refreshed tokens in { tokens_file } !" )
4144
4245 xbl_client = XboxLiveClient (auth_mgr )
4346
4447 # Some example API calls
4548 # Get friendslist
4649 friendslist = await xbl_client .people .get_friends_own ()
47- print (' Your friends:' )
50+ print (" Your friends:" )
4851 print (friendslist )
4952 print ()
5053
5154 # Get presence status (by list of XUID)
52- presence = await xbl_client .presence .get_presence_batch (["2533274794093122" , "2533274807551369" ])
53- print ('Statuses of some random players by XUID:' )
55+ presence = await xbl_client .presence .get_presence_batch (
56+ ["2533274794093122" , "2533274807551369" ]
57+ )
58+ print ("Statuses of some random players by XUID:" )
5459 print (presence )
5560 print ()
5661
5762 # Get messages
5863 messages = await xbl_client .message .get_inbox ()
59- print (' Your messages:' )
64+ print (" Your messages:" )
6065 print (messages )
6166 print ()
6267
6368 # Get profile by GT
6469 profile = await xbl_client .profile .get_profile_by_gamertag ("SomeGamertag" )
65- print (' Profile under SomeGamertag gamer tag:' )
70+ print (" Profile under SomeGamertag gamer tag:" )
6671 print (profile )
6772 print ()
6873
69- asyncio .run (async_main ())
74+
75+ asyncio .run (async_main ())
0 commit comments