Open MEINHL opened 2 years ago
Similarly, spO2 intraday is now available according to API docs.
Thanks!
In api.py, in the authorize_token_url function, the list of scopes need to be updated...
self.session.scope = scope or [
"activity",
"nutrition",
"heartrate",
"location",
"nutrition",
"profile",
"settings",
"sleep",
"social",
"weight",
"oxygen_saturation",
"respiratory_rate",
"temperature"
]
Also, I added a new function in api.py that should work for breathing rate and for spo2 (and maybe others). I say should because when I try it I get a 403 error back and I don't know why.
def intraday_time_series2(self, resource, base_date='today'):
"""
another one to handle spo2 and probably some others
"""
url = "{0}/{1}/user/-/{resource}/date/{base_date}/all".format(
*self._get_common_args(),
resource=resource,
base_date=self._get_date_string(base_date)
)
url = url + '.json'
return self.make_request(url)
If you copy that in and call fit_statsBR = auth2_client.intraday_time_series2('br', base_date="2022-05-14") it should work. But you'll probably get a 403 error instead. If you figure out why, let me know :)
I suspect it is a problem on the Fitbit side, not in this library. I have posted a question on their developers forum: https://community.fitbit.com/t5/Web-API-Development/Can-t-get-spo2-but-can-get-intraday-heart-rate/td-p/5200834
Thanks @mmcc-xx for your help and posting to the fitbit forum! :)
I receive the same 403 error and not sure why, but would also suspect it is a problem on the fitbit side....
You can try out the API calls with their Web API Explorer, which is described here: https://dev.fitbit.com/build/reference/web-api/troubleshooting-guide/debugging-tools/
I've also filled in the request form here to specifically ask for access to intraday data: https://dev.fitbit.com/build/reference/web-api/intraday/
No response yet.
I can get my own breathing rate data via the Web API Explorer, strange that this does not work with python as the library should be built on those very same calls!
My theory is that on the Fitbit side, the Web API Explorer has permission to get the data but our "Personal" applications don't (even though the documentation says that Personal apps are supposed to be able to access all data of the app owner).
I'm hoping that the request for intraday data I mentioned above will help things.
Update: I also submitted a support request with Fitbit. I hope that does something.
Here's the info I got from Fitbit support: _We've identified an issue with the personal application setting for querying intraday data from the new endpoints (SpO2, HRV, and Breathing Rate). While it is intended for personal applications to fetch this data, it is currently not behaving as expected today.
We're working with engineering to resolve this as soon as possible. In the meantime, I recommend continued use of the Web API Explorer to pull the data from your account._
That is great news, thanks for the update ! :)
Judging from this post https://community.fitbit.com/t5/Web-API-Development/Can-t-get-spo2-but-can-get-intraday-heart-rate/td-p/5200834
it seems that fitbit has fixed the issue with the personal authorization, however my python code above still fails with the same error.
Any ideas why this could be?
@mmcc-xx did it solve the issue for you ?
Bit late but if anyone is after intraday time series for breathing rate, HRV or SpO2 - I've just created a pull request that adds support for this:
Hi,
I am trying to export breathing rate data intraday by date, however could not find specific help on this in the python fitbit documentation. I have successfully authorized and then exported heart rate data, using the following call:
fit_statsHR = auth2_client.intraday_time_series('activities/heart', base_date="2022-05-14", detail_level='1sec')
However, breathing rate does not seem to work, even if it should be possible according to the fitbit documentation: https://dev.fitbit.com/build/reference/web-api/intraday/get-br-intraday-by-date/
I am using this call:
fit_statsBR = auth2_client.intraday_time_series('br', base_date="2022-05-14")
This is the error I get:
`HTTPNotFound Traceback (most recent call last) Input In [18], in <cell line: 1>() ----> 1 fit_statsBR = auth2_client.intraday_time_series('br', base_date="2022-05-14")
File ~\Documents\Projects\BBCDS\Actimetry\python-fitbit-master\fitbit\api.py:592, in Fitbit.intraday_time_series(self, resource, base_date, detail_level, start_time, end_time) 588 url = url + ('/%s' % (time_str)) 590 url = url + '.json' --> 592 return self.make_request(url)
File ~\Documents\Projects\BBCDS\Actimetry\python-fitbit-master\fitbit\api.py:256, in Fitbit.make_request(self, *args, *kwargs) 253 kwargs['headers'] = headers 255 method = kwargs.get('method', 'POST' if 'data' in kwargs else 'GET') --> 256 response = self.client.make_request(args, **kwargs) 258 if response.status_code == 202: 259 return True
File ~\Documents\Projects\BBCDS\Actimetry\python-fitbit-master\fitbit\api.py:99, in FitbitOauth2Client.make_request(self, url, data, method, kwargs) 89 method = method or ('POST' if data else 'GET') 90 response = self._request( 91 method, 92 url, (...) 96 kwargs 97 ) ---> 99 exceptions.detect_and_raise_error(response) 101 return response
File ~\Documents\Projects\BBCDS\Actimetry\python-fitbit-master\fitbit\exceptions.py:86, in detect_and_raise_error(response) 84 raise HTTPForbidden(response) 85 elif response.status_code == 404: ---> 86 raise HTTPNotFound(response) 87 elif response.status_code == 409: 88 raise HTTPConflict(response)
HTTPNotFound: <Response [404]>`
Is it possible to extract breathing rate, in the same way as heart rate data intraday by date?
Thank you!