OpenXbox / xbox-webapi-python

A python library to authenticate with Xbox Live via your Microsoft Account and provides Xbox related Web-API.
https://pypi.python.org/pypi/xbox-webapi
MIT License
175 stars 44 forks source link

How to handle multiple pages on result? #16

Closed kufhjer closed 3 years ago

kufhjer commented 4 years ago

How to handle multiple pages on result?

When fetching achievements; achievement_data = xbl_client.achievements.get_achievements_xboxone_gameprogress(token['token_xuid'], '1828326430') achievement_data = json.loads(achievement_data.text)

Part of the result is; 'pagingInfo': {'continuationToken': '32', 'totalRecords': 103},

How do I access the rest of the result? I need to make a new request but need to use the continuationToken.

kufhjer commented 4 years ago

Not possible with current script, ill add it and push it.

More info; https://docs.microsoft.com/en-us/gaming/xbox-live/xbox-live-rest/uri/marketplace/uri-inventoryget

JBrame commented 4 years ago

@BeLimitless guess you figured this out, but I did it like this. Note that I am querying the actual API URL not using the call provided but something similar should work.


headers = {'Authorization':'XBL3.0 x='+uhs+';'+XSTSToken}

continuationToken = ''

while True:
    response = APIhttp.http.get('https://achievements.xboxlive.com/users/xuid({})/achievements?continuationToken={}'.format(xuid,continuationToken),headers=headers)
    json_data = json.loads(response.text)
    continuationToken = json_data['pagingInfo']['continuationToken']
    if not continuationToken:
        break
    print(continuationToken)
kufhjer commented 4 years ago

@JBrame I used the build-in client to fetch the URL for achievements.

achievement_data = xbl_client.session.get("https://achievements.xboxlive.com/users/xuid(2535431190592405)/achievements?", params={'titleId': str(options['title_id']), 'continuationToken': int(continuation_token)}, headers={'x-xbl-contract-version': '2'})

tuxuser commented 3 years ago

achievement_data = xbl_client.session.get("https://achievements.xboxlive.com/users/xuid(2535431190592405)/achievements?", params={'titleId': str(options['title_id']), 'continuationToken': int(continuation_token)}, headers={'x-xbl-contract-version': '2'})

Since v2.0.10 you can do this finally in a native way:

await xbl_client.achievements.get_achievements_xboxone_gameprogress(
    '2535431190592405',
    title_id,
    extra_params={'continuationToken': continuation_token}
)