Giter Site home page Giter Site logo

python-wrapper's Introduction

Description

This is a Python wrapper for the unofficial Xbox API

Build Status

Installation

For now you will have to install manually, as I didn't upload the initial version to pypi (pip).

  1. Clone this repo
  2. Place the xboxapi directory in your project

The only dependency is requests library.

Usage

This is a basic example of how to create a client and fetch a gamers profile information from their gamertag.

from xboxapi import Client

client = Client(api_key=<api_key>)
gamer = client.gamer('voidpirate')

profile = gamer.get('profile')

Client class constructor takes the following optional arguments except api_key.

Argument Value Short Description
api_key string api token from Xbox API
timeout int how long until the request times out (seconds)
lang string country language code (e.g. for German (de-DE))

Client class public methods.

Method Value Optional Short Description
gamer(gamertag=<string>) string xuid=<string> gamertag to lookup
calls_remaining() n/a n/a Return headers about api rate limits

A note about the gamer method. If you already know the gamers xuid you can use that instead to avoid an additional api call when using only a gamertag.

Gamer class public methods, returned from gamer method in Client.

Method Value Optional Short Description
get(method=<string>) string term=<string> API calls.
send_message(message=<string>) string n/a Send a message to gamer
send_activity(message=<string>) string n/a Update your activity feed with a message

Pagination is supported in this client and all handled through get method. It works by detecting the response header for pagination, any subsequent calls to the same api endpoint will return paged data. If another api call is made to a different endpoint, the pagination token will be cleared and results will not be paged.

python-wrapper's People

Contributors

0verbyte avatar chadpaulson avatar darkwizz avatar djekl avatar jebby avatar jlax47 avatar minchinweb avatar slix69 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

python-wrapper's Issues

XboxApi doesn't exist

I'm following the instructions for your python wrapper

from xboxapi import XboxApi

but I'm given the "cannot import name..." error

Improve endpoint validation

It would be helpful to have valid endpoints store meta data about the endpoint itself, which would allow additional validation rules against the endpoints themselves.

An example rule could be.

[
'achievements' : {
  'requires_term' : True,
  'additional_fields' : ['sortDate']
}
]

This should help with #27 by logging any missing "fields" or "terms" when calling the endpoints.

Updated version to send a message.

So here is some basic code i have, but doesn't work. I'm pretty sure this code is wrong, i've gone through a few different setups but no luck...this is my latest one from a few days ago.

key = Client(api_key="MY_API_KEY")
player = key.gamer("A_RANDOM_NAME")
player.get('xuid')
player.send_message("TEST MESSAGE")

I'm just looking for an example of sending a message to person in Python3x+

Multiple message to sent

Hi,

I'm doing an Xbox tournament into the PUBG Game.
I would like to send the result of a game to each user.

So i need to send multiple messages to many users ( 60 to 90 players ).

The problem is, when i do that, i get errors :

  • It doesn't work for the 2nd user, so i tried to increase timeout => It doesn't work as expected
  • With the improvement of the timeout, i could send for 20 users only, but some aren't really sent ( and no error message ) and then stop.

Error Message I get :

Traceback (most recent call last):
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\urllib3\connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "", line 2, in raise_from
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\urllib3\connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "D:\Program Files\Python\lib\http\client.py", line 1331, in getresponse
response.begin()
File "D:\Program Files\Python\lib\http\client.py", line 297, in begin
version, status, reason = self._read_status()
File "D:\Program Files\Python\lib\http\client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "D:\Program Files\Python\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "D:\Program Files\Python\lib\ssl.py", line 1002, in recv_into
return self.read(nbytes, buffer)
File "D:\Program Files\Python\lib\ssl.py", line 865, in read
return self._sslobj.read(len, buffer)
File "D:\Program Files\Python\lib\ssl.py", line 625, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\urllib3\util\retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\urllib3\packages\six.py", line 686, in reraise
raise value
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\urllib3\connectionpool.py", line 306, in _raise_timeout
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='xboxapi.com', port=443): Read timed out. (read timeout=10)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/Tje/PycharmProjects/PUBGapi/pubg_script.py", line 173, in
client.gamer(gamertag=tmm_result['GT']).send_message(message=str_to_send)
File "C:\Users\Tje\PycharmProjects\PUBGapi\xboxapi\gamer.py", line 93, in send_message
return self.client.api_post('messages', payload)
File "C:\Users\Tje\PycharmProjects\PUBGapi\xboxapi\client.py", line 87, in api_post
timeout=self.timeout)
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\requests\api.py", line 116, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\requests\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\requests\sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Tje\PycharmProjects\PUBGapi\venv\lib\site-packages\requests\adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='xboxapi.com', port=443): Read timed out. (read timeout=10)

Typos in request list in the documentation.

In the documentation there are 3 misspelled requests:

get_xuid_by_gametag()
get_gametag_by_xuid()
get_user_gamecard()

Those didn't work for me so I looked into the source and it defines them as:
get_xuid_by_gamertag()
get_gamertag_by_xuid()
get_user_gamercard()

All 3 are missing the "r" in gamer

Claiming tags?!

How to claim tags using this api?
Let me know if you need more details.

xboxapi not Work?

Hello,
Is xboxapi.com not working?
I tried to test api via Curl but it does not return the data.

Achievements by game

Hi! at this moment I'm playing with your API. Is there some way to get achievements by game instead by a user? Or some tip to do that?

I can get achievements if my profile has this game or if I know somebody who has played it.

Thanks for your time!

Refactor log levels

As of now the only logging that gets triggered is setting a debug flag in the code. Since the logging interface is supported, the logger should handle the levels themselves.

Xbox clubs

I was wondering if this API can be used for Xbox clubs. There are people who struggle heavily in a given activity in a game I play and I would like to create some way of looking over the xbox club app and help them with the given activity. Is this at all possible with your package?

401 Unauthorized Responses

Hi,

I am new here and am really excited to see what I could do with this awesome api for xbox :D

I am running into issues, however. For some reason, I am getting 401 Unauthorized errors at unexpected times. I am trying to use this request:

GET https://xboxapi.com/v2/2533274813099285/game-stats/950328474
and I have my X-Auth header with my api key.

For some reason, I can run this code fine in Postman and get a 200 response back. When I try to run this from my C# code it gives me a 401 Unauthorized.

This xuid is my friend's so I don't know if that is the issue and I can't make the request without him having his own api key? In my head, it wouldn't make sense for everyone that uses the app to have to have a separate api key. Also, it wouldn't make sense because since it worked in Postman I know it is possible.

Any ideas on what I could be doing wrong?

I have tried regenerating my api key.
Also, sometimes the request won't work for my own xuid when it has a few minutes before. I am fairly confused as to what is going on.

Any help is appreciated.

Thanks,
hogiyogi597

Pulling Games Coming Soon and Latest Games Returns no games

Whenever I call anyone of these end points I just get:

{"Id":"Lists","Name":"Lists","Version":"v8.0","ContinuationToken":"d92bb98e-844a-4ec6-9d1d-4a79d6ded0ad","Items":[{"Id":"9PD6X6PNG5B0","ItemType":"Game","PredictedScore":34.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9PLW0DRNHMF2","ItemType":"Game","PredictedScore":35.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9MX1ZZ46W88X","ItemType":"Game","PredictedScore":36.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9NCJR504WXT0","ItemType":"Game","PredictedScore":37.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9NV8MJZ96J4K","ItemType":"Game","PredictedScore":38.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9MWGHSQZ6HL6","ItemType":"Game","PredictedScore":39.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9P1LXTT8V2B4","ItemType":"Game","PredictedScore":40.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9P9MTMWKS82R","ItemType":"Game","PredictedScore":41.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9PCPXQ5K8SV5","ItemType":"Game","PredictedScore":42.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9PHNNXSRN7NK","ItemType":"Game","PredictedScore":43.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9PNS9G2ZZV88","ItemType":"Game","PredictedScore":44.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9NKG0X1MGQTX","ItemType":"Game","PredictedScore":45.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9NZC09NNR93L","ItemType":"Game","PredictedScore":46.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9NX3G3Z38CV2","ItemType":"Game","PredictedScore":47.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9P6PXDC2SXVR","ItemType":"Game","PredictedScore":48.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9MZXV7ZGM0J5","ItemType":"Game","PredictedScore":49.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9NKCGC1XV8VL","ItemType":"Game","PredictedScore":50.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9PF7G7PQ02JW","ItemType":"Game","PredictedScore":51.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9N9KG3XJM5PT","ItemType":"Game","PredictedScore":52.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9NHLKLVDGQBZ","ItemType":"Game","PredictedScore":53.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9N30NRTCRCGH","ItemType":"Game","PredictedScore":54.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9PCBJLHPDM0H","ItemType":"Game","PredictedScore":55.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9NM6JN1XRC7S","ItemType":"Game","PredictedScore":56.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9NWQ4TJKPJ7B","ItemType":"Game","PredictedScore":57.0,"TrackingId":"00000000-0000-0000-0000-000000000003"},{"Id":"9N4H8L9S2H7D","ItemType":"Game","PredictedScore":58.0,"TrackingId":"00000000-0000-0000-0000-000000000003"}],"Title":"New games","LongTitle":"New games","PagingInfo":{"TotalItems":967},"Status":"Success"}

And those IDs don't seem to give back any achievement information. Is there a way to pull a list of all titleID's or even productID's from a titleID?

I'm noticing a continuation token which I didn't notice before. I'll see if that helps. But my question still stands. Is there a way to do either or both of those things?

EDIT: Using the continuation token didn't seem to help.

Client API version 2

The current implementation is very manual as far as method definitions go. Version 2 should be written in a more OOP approach, in addition the current implementation should still be maintained for backwards compatibility. Perhaps a flag to the xboxapi constructor to trigger the new schema? Some ideas:

  • Single API class which defines each HTTP endpoint in an iteration, rather than methods for each endpoint. Endpoints that simply return JSON should map accordingly. xbox.get('profile')
  • Profile class which should encapsulate functionality specific to the user itself (e.g. sending messages, getting followers, etc). This will allow for objects for multiple users. As it is currently, each method takes the user id, which can be tedious to manage for the user.

Product ID of Game

Hi there,

great API so far :)

BUT:
how can I find out the product_id of a game?
Is it possible to search for a game?

I need the product_id to fetch further information about the game.

Thanks for any help.

I cant send messages?

I tried making a basic messenger with this script:

import requests

from xboxapi import XboxApi

api = XboxApi(api_key="MyApiKeyHere")

xuids = raw_input("Enter the Gamertag you would like to look up: ")
message = raw_input("Enter the message text you would like to send: ")


WhoIsThis = api.get_xuid_by_gamertag(xuids)


SendMessage = api.send_message(message, xuids)

print SendMessage
Pause = raw_input("Press enter to close prompt")

But whenever I run the script I get this error:

{u'errorCode': 1001, u'errorSource': u'UserInboxFrontEnd'}

Could you possibly tell me how to fix this or what I'm possibly doing wrong?

404 when using 'achievements' method

This library looks great and I'd really like to use it to get some achievement data but I'm having issues. I've received an API key and i've successfully made a request to get my profile, but when I try to use the "achievements" method, I get a 404 page. Any help in getting this working?

from xboxapi import Client
from settings import API_KEY

client = Client(api_key=API_KEY)
gamer = client.gamer('gamertag')

# this line works
profile = gamer.get('profile')

# the below line requests the url https://xboxapi.com/v2/<<XUID>>/achievements,
# which goes to the 404 page
# the console prints out "ERROR:xboxapi:XboxAPI error: (404) Not Found"
achievements = gamer.get('achievements')

API Keys do not work

I've used this program before many times, so I'm sure I'm following it correctly. Any ideas?

image

Gamertag availablility

Hi Alan/XboxTeam,

Thanks for your reply on my previous post.

I'm creating a new issue, since last one was closed.

Could you possibly share a small snippet demonstrating how to check if a
gamertag is available?

I would really appreciate your help.

Thanks,
Ronnie

On Fri, May 10, 2019 at 7:48 PM Alan Wynn [email protected] wrote:

Closed #31 #31.

โ€”
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#31 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADBTGMSUNCJVLSVVEW4V53DPUV72RANCNFSM4HMCB7EA
.

Originally posted by @ronnielivingsince1994 in #31 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.