FitBit API "Get Activity TCX" Not Returning The Expected Content (Response Code 200)

131 views Asked by At

I have tried for hours getting the content of the .tcx file via the fitbit api. But, with no luck. I have no issue getting "Heartrate-, Sleep- og Profile data i.e.". Maybe I can't get the .tcx data simply because it's .tcx format, and not .json format?

According to the FitBit Developer Reference:

  • "Response Code 200 = A successful request."
  • Response should be in an XML format

Any help would be greatly appreciated, thanks :-)

import requests
import json

# Connect to API using Implicit Grant Flow
access_token = 'eyJhbGciOXXXXI1NiJ9.eyJhdWXiOiIyMXXXU0giLCJzdWIiOiI0WU5HM1EiLFFUEOWMiOiJGaXRiaXQXXXeXAiOiJhY2Nlc3NfdG9rZWXiLCJzY29wZXMiOiJ3584WF3BybyB3bnV0IHdzbGUgd3dXXXXc29jIHdhY3Qgd3NlXCB3bG9jIiwiZXXXXjoxNjQxNXXXMDc1LCJpYXQiOjE2XXXXXDc0ODR9.cuioifVTTG1ThUWXXAQH1Y816dTnWXXXkfsyANc-Qc'

# Get TCX Data
def get_activity_tcx():
    logid = '44962596407'
    url = f'https://api.fitbit.com/1/user/-/activities/{logid}.tcx?'
    header = {'Authorization' : 'Bearer {}'.format(access_token)}
    response = requests.get(url, headers=header)
    return response

get_activity_tcx())

Output

<Response [200]>
0

There are 0 answers