Just adding this here in case it is useful. The Strava API also has the ability to download data streams (see here API Documentation). I believe this gives slightly more info such as private activities and GPX points within privacy zones etc. assuming the API scope is set to read_all.
I was using the API with Python but I assume it works basically identically in Java. Also note I am just doing this as a hobby so there is likely a more efficient way to do the following...
Example on creating gpx file available here
The code below should download data streams from the Strava API and then generate a GPX file from these data streams.
import requests as r
import pandas as pd
import json
import gpxpy.gpx
from datetime import datetime, timedelta
#This info is in activity summary downloaded from API
id = 12345678 #activity ID
start_time = '2022-01-01T12:04:10Z' #activity start_time_local
#get access token for API
with open('config/strava_tokens.json') as f:
strava_tokens = json.load(f)
access_token = strava_tokens['access_token']
# Make API call
url = f"https://www.strava.com/api/v3/activities/{id}/streams"
header = {'Authorization': 'Bearer ' + access_token}
latlong = r.get(url, headers=header, params={'keys':['latlng']}).json()[0]['data']
time_list = r.get(url, headers=header, params={'keys':['time']}).json()[1]['data']
altitude = r.get(url, headers=header, params={'keys':['altitude']}).json()[1]['data']
# Create dataframe to store data 'neatly'
data = pd.DataFrame([*latlong], columns=['lat','long'])
data['altitude'] = altitude
start = datetime.strptime(start_time, "%Y-%m-%dT%H:%M:%SZ")
data['time'] = [(start+timedelta(seconds=t)) for t in time_list]
gpx = gpxpy.gpx.GPX()
# Create first track in our GPX:
gpx_track = gpxpy.gpx.GPXTrack()
gpx.tracks.append(gpx_track)
# Create first segment in our GPX track:
gpx_segment = gpxpy.gpx.GPXTrackSegment()
gpx_track.segments.append(gpx_segment)
# Create points:
for idx in data.index:
gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(
data.loc[idx, 'lat'],
data.loc[idx, 'long'],
elevation=data.loc[idx, 'altitude'],
time=data.loc[idx, 'time']
))
# Write data to gpx file
with open('output.gpx', 'w') as f:
f.write(gpx.to_xml())
I've just added a python code to GitHub that should hopefully download all a users GPX files from Strava.