thegameofcode / fitbit-client-oauth2 Goto Github PK
View Code? Open in Web Editor NEWAn OAuth 2.0 client to consume Fitbit's API
Home Page: http://www.fitbit.com/
An OAuth 2.0 client to consume Fitbit's API
Home Page: http://www.fitbit.com/
api.js line 29 //TODO: improve this way of getting the token
Being new to a lot of this stuff, this undocumented data schema dependency has had me scratching my head for a bit :)
Might you do the TODO soon?
Or do you have a preferred solution to this?
N.B. this was exposed by your two fitbit projects having incompatible names :
( Obviously I prefer to use passport, but I also want to use your API functions! )
So a quick and dirty fix for me was to rename where it's saved to suit this project.
from passport-fitbit-oauth2 project example :
var fitbitStrategy = new FitbitStrategy({
clientID: CLIENT_ID,
clientSecret: CLIENT_SECRET,
scope: ['activity','heartrate','location','profile'],
callbackURL: "http://localhost:3000/auth/fitbit/callback"
}, function(accessToken, refreshToken, profile, done) {
// TODO: save accessToken here for later use
done(null, {
access_token: accessToken, **// MODIFIED was accessToken**
refreshToken: refreshToken,
profile: profile
});
});
Then this whole user object can be passed to the API function in this fitbit-client-oauth2 project.
Hi,
This is the error I'm getting in regards to using your example code. Also, things have also been apparently deprecated. Maybe you can take a look? Thanks.
body-parser deprecated bodyParser: use individual json/urlencoded middlewares auth_server.js:13:9
body-parser deprecated undefined extended: provide extended option ../node_modules/body-parser/index.js:105:29
express deprecated res.send(status, body): Use res.status(status).send(body) instead auth_server.js:38:11
Currently sets the date as :
date: moment().format('YYYY-MM-DD'),
If the user isn't in the same timezone as the server, this will result in the data getting reset to zero at the wrong time ( from the users perspective ).
It seems to work fine just setting :
date: 'today'
Although I've not tested the rollover yet, this would be Fitbit's problem if it goes wrong...
in line 73 of src/helpers.js buildIntradayTimeSeriesOptions() doesn't add startTime, endTime if set in options.
patch:
-- url.replace('{extra}', extra);
++ url = url.replace('{extra}', extra);
looks like fitbit's OAuth 2.0: Authorization URI is: https://www.fitbit.com/oauth2/authorize
the config file here sets the base url to:
const FITBIT_BASE_API_URL = 'https://api.fitbit.com';
causing a 404 when attempting to authorize.
This could entirely be my own fault, as I think I'm doing something wrong, but after reading through the src/auth.js file I've been implementing my refresh like:
var fitbitTokens = {
access_token: user.access_token,
refresh_token: user.refresh_token,
expires_in: 3600
};
client.refreshAccessToken(fitbitTokens)
.then(function (new_token) {
// save new_token.access_token
// save new_token.refresh_token
// save new_token.expires_in
// save new_token.expires_at
}).catch(function(err) {
console.log('error refreshing user token', err);
});
The problem is... it doesn't actually refresh! new_token comes back with the same access_token as before, and that could be as intended but I get a 401 error back from fitbit because the refresh isn't actually successful. Any thoughts?
Is there something else I should be doing with new_token instead of just saving new_token.access_token, new_token.refresh_token, new_token.expires_in, and new_token.expires_at to my db?
since the update, doing an intraday time series request the api points me to the wrong url:
options:
{ url: 'https://fitbit.com/1/user/-/activities/steps/date/today/today/15min.json',
method: 'GET',
json: true,
thanks for any help
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.