How can I access the Google Fit API to get my steps data?

Hello,

I’m currently working on accessing Google Fit data using its API. I have successfully set up the credentials with the Google OAuth2 API and have specified the scope as https://www.googleapis.com/auth/fitness.activity.read The connection is established, and when I send an HTTP request to https://www.googleapis.com/fitness/v1/users/me/dataSources, I receive a dataSource in response. However, when I try to make a request to https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate, I encounter an error. I’m trying to identify what I might be doing wrong in this case.

Regards.

Hey @mallugamer4k,

The API is saying the URL is wrong, Are you sure the dataset:aggregate path is correct?

1 Like

Hello, thank you for your reply. I believe it is. As per the google developer reference link.

Hey @mallugamer4k,

Looking at that link the request method should be a post and you have it set to Get, try changing it and see if that works.

1 Like

Thank you, Jon. That was it. Also as per this link. I should be getting the total daily steps with the code. I’m getting the result, but with empty arrays? Am I doing this wrong?

Regards.

Hey @mallugamer4k,

I don’t use Google Fit so it is hard to check if the data is correct but are your timestamps correct in your request?

1 Like

Hey Jon, I guess they are. But let me try adjusting the code and check. As per the google developer example it should give me a total amount of steps for the day.

Hey @mallugamer4k,

The bit that caught my eye was the start and end times, Your example is using 2 dates from August 2015 so you would need to update that unless you are specifically looking for back then.

1 Like

Hello Jon, I appreciate your replies. Indeed, the start and end times were the key issue. Therefore, I configured a function node to retrieve the current day as a Unix timestamp, as needed, and subsequently connected it with the HTTP request.

1 Like

Hey @mallugamer4k,

You might have been able to do it with an expression as well using Luxon to handle the formatting but that can be for a future iteration of the workflow once you are happy with it :slight_smile:

Luxon in n8n: Date and time with Luxon | n8n Docs
Luxon formatting cheat sheet: luxon/docs/formatting.md at master · moment/luxon · GitHub

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.