Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Weekly Goals

ANSWERED

I'm writing a new watch face and want to access the progress towards the weekly goal for active minutes.  I have an Ionic and can swipe up to access the activity details where it shows how many days I've hit my active minutes goal for the week.

 

I've looked through the documentation on "user-active" and found info on how to set listeners to fire when you reach a goal, but everything seems geared around today.  I want to know how many days a given goal (activeMinutes specifically) have been reached so I can show it on the watch.

 

It seems like this should be info stored on the watch, but if I have to go out to the companion to get it, I'll do that.

 

Thanks

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

I think that approach should basically work. To get around the exception, try doing a statSync() before opening/reading. Failing that, you could use listDirSync() but I've never found it necessary to go to that length.

If that isn't the problem, it could be something to do with the way in which the data is formatted. I've found that the watch is fussier than the sim.

You might also want to check whether the reachgoal event fires AFTER the goal has been met, in case your clockface wasn't running at the exact time. If not, you could check the achievement level 'manually'; that should work so long as the clockface gets started later on the same day. If it doesn't, using the web API would be the only workaround, I think.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
8 REPLIES 8

It's currently only available via the Web API, so you'd need to fetch it via the companion.

 

https://dev.fitbit.com/build/reference/web-api/activity/#activity-goals

 

There's an example of using our Web API in a companion here https://github.com/Fitbit/sdk-oauth

Best Answer
0 Votes

Thanks for the quick reply.  I attempted to query this end point to get the weekly goal data:

https://api.fitbit.com/1/user/-/activities/goals/weekly.json

 

But this is the response I get:

{"errors":[{"errorType":"system","fieldName":"n/a","message":"Authorization Error: Invalid authorization token type"}],"success":false}

 

I am attempting to call this from the companion part of my watch program.  When I looked up authorization, all I could find was info about external applications.  How do I pass along the correct auth for the current user of the watch?

 

Thanks!

Best Answer
0 Votes

I'm still confused about what I need to do here.  The OAuth example says I need ot register a web app, but I am just writing a clock face.  I want to hit end points related to Goals and Sleep logs for the watch user.  Do I really need to register an app to do that?  Seems like there should be an easier way to get data for the current user.  Thanks

Best Answer
0 Votes

I was able to follow the oauth example by registering my watch face as an app.  But the response to the activity end points doesn't seem to have what I want.  I just want info about which days the user hit the active minutes goal for the current week.  Is there an end point for that or do I need to subscribe to the event for hitting the goal and store it locally?  Thanks

Best Answer
0 Votes

The on device goals are here https://dev.fitbit.com/build/reference/device-api/user-activity/#variable-goals

Here's an example

import { goals, today } from "user-activity";
goals.onreachgoal = function(evt) {
  // check each metric, see which has been met or exceeded
   if (today.adjusted.steps >= goals.steps {
     // yay
  }
}
Best Answer
0 Votes

That isn't quite what I'm looking for, at least I don't think it is.  I want to know the number of days that the user has hit the active goal during the current week.  I am currently trying to achieve the same thing by hooking into this:

goals.addEventListener("reachgoal", (goal, evt) => {...})

The problem I'm having with that solution is needing to persist the data so past days are kept if the clock app has to reload.  I'm trying to use the fs interface to read/write a small file with the running total of active days.  It seems to work in the simulator, but when I upload it to my watch, the file not being there causes an exception and the app fails to continue even though I have the code in a try {} catch (e) {} block.

Best Answer
0 Votes

I think that approach should basically work. To get around the exception, try doing a statSync() before opening/reading. Failing that, you could use listDirSync() but I've never found it necessary to go to that length.

If that isn't the problem, it could be something to do with the way in which the data is formatted. I've found that the watch is fussier than the sim.

You might also want to check whether the reachgoal event fires AFTER the goal has been met, in case your clockface wasn't running at the exact time. If not, you could check the achievement level 'manually'; that should work so long as the clockface gets started later on the same day. If it doesn't, using the web API would be the only workaround, I think.

Peter McLennan
Gondwana Software
Best Answer

The code seems to work, but I'm confused by how it is tracked in the app software.  My daily active goal is set to 30min, but the companion said I completed 2 days this week - 1 for a 20min treadmill run, and 1 for a 17min walk.  Neither register with the logic I have in my clock app because they aren't greater than the active minutes goal.  Am I testing the wrong thing or linked to the wrong event here?  I want to reflect the same data that the "Track exercise" tile in the main Dashboard screen on the companion app shows.  Thanks

Best Answer
0 Votes