Page 2 of 2 FirstFirst 12
Results 21 to 26 of 26
  1. #21

    AW: Re: Battlefield 1 API

    Hi,

    I tried the Postman as a last resort and it worked. Thank you!
    Only issue is, that I don't know how can I get the X-Gatewaysession automatically.
    Do you have any advice for that?

    Thank you

  2. #22

    Re: Battlefield 1 API

    you only need to request Gatewaysession one time. e.g. via browser

  3. #23

    AW: Battlefield 1 API

    Hello,

    I finally got this working with Python! Thanks to sbauer318 JS and H3iMDAII87 curl command.

    Here is the complete script I used:

    import requests
    import json

    s = requests.Session()
    personaid = personal id from companion site in url
    rnd_id = 'c63929d3-3501-4113-a9d9-4bd416d4bedc' (random id)

    init_url = 'https://www.battlefield.com/login?postAuthUri=/companion'
    companion_url = 'https://companion-api.battlefield.com/jsonrpc/web/api?Stats.getCareerForOwnedGamesByPersonaId'
    ea_token = 'https://accounts.ea.com/connect/auth?client_id=sparta-companion-web&response_type=code&prompt=none&redirect_uri=nu cleus:rest'
    auth_code = 'https://companion-api.battlefield.com/jsonrpc/web/api?Companion.loginFromAuthCode'

    email = your_email
    password = your_password

    init = s.get(init_url)

    login_payload = {
    '_eventId': 'submit',
    'password': password,
    'email': email
    }

    ea_login = s.post(init.url, data=login_payload)
    ea_code = (json.loads((s.get(ea_token)).text))['code']

    session_data = {"jsonrpc":"2.0",
    "method":"Companion.loginFromAuthCode",
    "params":{"code": ea_code,"redirectUri":"nucleus:rest"},
    "id":rnd_id}

    session_id = (json.loads((s.post(auth_code, data=json.dumps(session_data))).text))['result']['id']

    headers = {
    'Content-Type': 'application/json',
    'Accept': '*/*',
    'X-GatewaySession': session_id
    }
    data = {"jsonrpc":"2.0","method":"Stats.getCareerForOwned GamesByPersonaId","params":{"personaId"ersonaid},"id":rnd_id}

    companion_data = s.post(companion_url, headers=headers, data=json.dumps(data))

    print(companion_data.text)

    s.cookies.clear()

  4. #24

    Re: AW: Battlefield 1 API

    Quote Originally Posted by theManag3R View Post
    Hello,

    I finally got this working with Python! Thanks to sbauer318 JS and H3iMDAII87 curl command.
    ...
    Awesome! Thanks a million for sharing

    I just finished creating a script for node.js!

    https://github.com/MattMcFarland/battlefield-companion

    Also, I still used some of the python script you shared, however I made some revisions based on best practices via pylint.

    Here is a python script for just getting the paramater needed for X-GatewaySession:

    Code:
    """Get Auth Token for battlefield1 companion"""
    import json
    import sys
    import uuid
    # Non standard libraries
    import requests
    
    SESSION = requests.Session()
    
    INIT_URL = 'https://www.battlefield.com/login?postAuthUri=/companion'
    EA_AUTH_URL = ('https://accounts.ea.com/connect/auth?'
                   'client_id=sparta-companion-web&'
                   'response_type=code&'
                   'prompt=none&'
                   'redirect_uri=nucleus:rest')
    API_CODE_URL = 'https://companion-api.battlefield.com/jsonrpc/web/api?Companion.loginFromAuthCode'
    
    AUTH_EMAIL = str(sys.argv[1])
    AUTH_PASSWORD = str(sys.argv[2])
    
    INIT = SESSION.get(INIT_URL)
    
    AUTH_PAYLOAD = {
        '_eventId': 'submit',
        'password': AUTH_PASSWORD,
        'email': AUTH_EMAIL
    }
    
    EA_LOGIN = SESSION.post(INIT.url, data=AUTH_PAYLOAD)
    EA_AUTH_CODE = json.loads(SESSION.get(EA_AUTH_URL).text)['code']
    
    SESSION_DATA = {
        "jsonrpc": "2.0",
        "method": "Companion.loginFromAuthCode",
        "params":
            {
                "code": EA_AUTH_CODE,
                "redirectUri":"nucleus:rest"
            },
        "id": str(uuid.uuid4)
    }
    
    SESSION_ID = json.loads(
        SESSION.post(
            API_CODE_URL,
            data=json.dumps(SESSION_DATA)
        ).text)['result']['id']
    
    SESSION.cookies.clear()
    
    print SESSION_ID
    You can see the code as written here: https://github.com/MattMcFarland/bat...ython/token.py

  5. #25

    Re: Battlefield 1 API

    For those interested, I've finished up a stats library that proxies to battlefieldtracker - You can see it here: https://github.com/MattMcFarland/battlefield-stats

    You can also use an express middleware if you want to serve up your own JSON api in a flash, you can see that here: https://github.com/MattMcFarland/bat...-stats-express

    Now if you want to use the companion API directly, I've got one working too, but it doesn't have as many features and I don't recommend it, however you can find it here: https://github.com/MattMcFarland/battlefield-companion

    I'm super excited and spent alot of work on these, so I hope some of you find it useful

  6. #26

    Re: Battlefield 1 API

    How are you able to determine the personaId for someone else based on their platform's id. For example if I had a friend on xbox with the username = "player123", is there an api call like getPersonaIdByUsername("player123") ?

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
P-STATS NETWORK FORUM LOGIN CREATE ACCOUNT