Bungie-net / api

Resources for the Bungie.net API
Other
1.22k stars 92 forks source link

How get PostGameCarnageReport data in D1 and D2? #372

Open ynorouzz opened 6 years ago

ynorouzz commented 6 years ago

To get PostGameCarnageReport , I need activityId. For D2 I used the following method:

for chId in characterIds:
        print 'Destiny2.GetActivityHistory'
        ch_url = base_urld2 + "/" + memType + "/Account/" + memId + "/Character/" + chId + "/Stats/Activities/"
        ch_res = requests.get(ch_url, headers=HEADERS)
        print ch_res.json()['Response']

but the response is empty. For D1 I used the following script:

for chId in characterIds:
    ch_url = base_urld1+"/Stats/AggregateActivityStats/"+memType+"/"+memId+"/"+chId+"/"
    ch_res = requests.get(ch_url, headers=HEADERS)
    print ch_res.json()['Response']['data']['activities']

    for act in ch_res.json()['Response']['data']['activities']:
        url = base_urld1+"/Stats/PostGameCarnageReport/"+ str(act['activityHash'])
        res = requests.get(url, headers=HEADERS)
        print  res.json()['Response']['data']

and it shows activities, but when I use activityHash to get PostGameCarnageReport, the response only includes entities, not teams.

ykslebutv commented 6 years ago

Your URL for getting activities for D2 looks correct. You might try adding mode, count and page parameters to it, like so (but it should work without them):

... + "/Stats/Activities/?mode=AllPvP&count=50&page=0"

Are you sure the membership ID and character ID point to a valid character that does have activities?

As for PostGameCarnageReport you need to use activityDetails.instanceId, not activityHash.

ynorouzz commented 6 years ago

I changed the script as follows that works for D2 (for a new player), but not D1. In D1, script can not find ActivityHistory of the given players.

def extract_PGCR(memId, chId, memType, dataPath, fname, destinyVersion):

#1 GetActivityHistory
if destinyVersion == 2:
    hist_url = "https://www.bungie.net/Platform/Destiny2/"+str(memType)+"/Account/"+str(memId)+"/Character/"+str(chId)+"/Stats/Activities/"
elif destinyVersion == 1:
    hist_url = "https://www.bungie.net/d1/platform/Destiny/Stats/ActivityHistory/"+str(memType)+"/"+str(memId)+"/"+str(chId)+"/"
    his_res = requests.get(hist_url, headers=HEADERS).json()

data = []
# 2 GetPostGameCarnageReport
# /Destiny2/Stats/PostGameCarnageReport/{activityId}/
if his_res['Response']:
    for act in his_res['Response']['activities']:

        if destinyVersion == 2:
            hist_url = "https://www.bungie.net/Platform/Destiny2/Stats/PostGameCarnageReport/"+act['activityDetails']['instanceId']+"/"
        elif destinyVersion ==1:
            hist_url = "https://www.bungie.net/d1/platform/Destiny/Stats/PostGameCarnageReport/"+act['activityDetails']['instanceId']+"/"

        his_res = requests.get(hist_url, headers=HEADERS).json()

        data.append(his_res)
        with open(dataPath+fname+'_PGCR.json', 'w') as fp:
            json.dump(data, fp)

    return data
xlxCLUxlx commented 6 years ago

Hi @ynorouzz,

For your Destiny 1 call to the ActivityHistory end point you will need to add the 'mode' parameter which looks to be missing from your code snippet and a required parameter.

Based on the ActivityHistory link I provided above the values for mode can be as follows:

None, Story, Strike, Raid, AllPvP, Patrol, AllPvE, PvPIntroduction, ThreeVsThree, Control, Lockdown, Team, FreeForAll, Nightfall, Heroic, AllStrikes, IronBanner, AllArena, Arena, ArenaChallenge, TrialsOfOsiris, Elimination, Rift, Mayhem, ZoneControl, Racing, Supremacy, PrivateMatchesAll

So if you wanted to get all activities your 'hist_url' should look like the following:

hist_url = "https://www.bungie.net/d1/platform/Destiny/Stats/ActivityHistory/"+str(memType)+"/"+str(memId)+"/"+str(chId)+"/?mode=none"

Example:

https://www.bungie.net/d1/Platform/Destiny/Stats/ActivityHistory/1/4611686018429681104/2305843009217260609/?mode=none

Regards, @xlxCLUxlx

ynorouzz commented 6 years ago

Hi @xlxCLUxlx ,

Excellent. Thank you for your comments.

Best regards