05-14-2019 20:25
05-14-2019 20:25
Hi all,
I am new to this but I am looking to create a watch face on an ionic that displays the water goal and how much water has been drunk in a day (using the data in the fitbit app / today data). Something similar to the goal for steps. Has anyone done this you would anyone know if this is even possible?
Michael
05-15-2019 01:30
05-15-2019 01:30
That data is available in the Food Logging Web API:
https://dev.fitbit.com/build/reference/web-api/food-logging/
You can see an example of fetching data from the Web APIs here:
05-15-2019 23:11
05-15-2019 23:11
Thanks for pointing me in the right direction.
Have you or anyone else seen a working example of this on a clock face?
05-16-2019 03:42
05-16-2019 03:42
You can take a look at the Water Logged app for ideas - https://github.com/TylerLeonhardt/Water-Logged
01-17-2021 12:54
01-17-2021 12:54
I am also interested in making a watch face that shows the amount of water done for the day and goal, I expected it to be part of the activity info, to be honest.
Checking WaterLogged's source code I understand that it relies on the companion mobile app. The watch app uses the `messaging` package to request data to the companion app, which then uses the `request` package to communicate with the WebAPI.
Is it possible to read water data without needing to develop a companion app as an intermediate?
01-17-2021 13:03
01-17-2021 13:03
Unfortunately not. The companion app is the only code with which the watch can communicate directly.
01-17-2021 14:00
01-17-2021 14:00
Got it, thanks for your prompt response @Gondwana. So the companion app would be making requests for water data directly to fitbit's WebAPI.
I am quite new to FitBit development and have a question about authentication. Do I still need to register an App? If so, since the companion will make requests directly to fitbit WebAPI without an intermediate server, how should I go about the Callback URL?
Cheers
01-17-2021 14:10
01-17-2021 14:10
I think you're talking about a Web API App. You don't need one for what you're describing: you can get data from the Web API directly into your companion app using the oath settings component.
Here's another repo that pulls data from Web API into companion. It does use a separate server, but not to get the data.
01-17-2021 16:07
01-17-2021 16:07
@Gondwana thanks for the suggestion, I checked ou the repos fitbit-rhr-fetcher, sdk-oauth and the documentation. I created a settings page with an OAuth Button, just to log the token for now (code below). When I hit the button, I get redirected to an error page with the following message:
The app you're trying to connect did not provide valid information to Fitbit. Please report this issue to them.
Developer information: invalid_request - Invalid redirect_uri parameter value
I used a valid HTTPS URL as Callback in my test app, and I noticed that no request was made to it.
App configuration
settings/index.jsx
function mySettings(props) {
return (
<Page>
<Section
title={<Text bold align="center">Fitbit Account</Text>}>
<Oauth
settingsKey="oauth"
title="Login"
label="Fitbit"
status="Login"
authorizeUrl="https://www.fitbit.com/oauth2/authorize"
requestTokenUrl="https://api.fitbit.com/oauth2/token"
clientId="XXXXXXXXXXXX"
clientSecret="XXXXXXXXXXXXX"
scope="nutrition"
/>
</Section>
</Page>
);
}
registerSettingsPage(mySettings);
companion/index.js
import { settingsStorage } from "settings"
// A user changes Settings
settingsStorage.onchange = evt => {
if (evt.key === "oauth") {
// Settings page sent us an oAuth token
console.log(evt.newValue)
}
};
Any idea of what I am doing wrong here?
Thanks!
01-17-2021 16:28
01-17-2021 16:28
The error above was solved by using https://app-settings.fitbitdevelopercontent.com/simple-redirect.html as Callback URL. Yay \o/