Coder Social home page Coder Social logo

node-fitbit's Introduction

Fitbit API Client for Node.js Build Status

Currently a read only implementation for reading data from the Fitbit API as an authenticated user.

### TODO

I've split this into two sections, top section is what I need to have for the project I created this module for and the latter is what the API supports.

Needed by me:

  • Add user model
  • Add time series data for models
  • Allow data models to be updated("logged") and deleted via the API

Supported by API:

  • Add Blood pressure, heart rate, glucose resource models
  • Add goals for all models that support them
  • Collection metadata models
  • Anything else...

Installation

npm install fitbit

Usage

Below is an example usage for authenticating and making a resource request:

var express = require('express')
  , config = require('./config/app')
  , app = express()
  , Fitbit = require('fitbit');

app.use(express.cookieParser());
app.use(express.session({secret: 'hekdhthigib'}));
app.listen(3000);

// OAuth flow
app.get('/', function (req, res) {
  // Create an API client and start authentication via OAuth
  var client = new Fitbit(config.CONSUMER_KEY, config.CONSUMER_SECRET);

  client.getRequestToken(function (err, token, tokenSecret) {
    if (err) {
      // Take action
      return;
    }

    req.session.oauth = {
        requestToken: token
      , requestTokenSecret: tokenSecret
    };
    res.redirect(client.authorizeUrl(token));
  });
});

// On return from the authorization
app.get('/oauth_callback', function (req, res) {
  var verifier = req.query.oauth_verifier
    , oauthSettings = req.session.oauth
    , client = new Fitbit(config.CONSUMER_KEY, config.CONSUMER_SECRET);

  // Request an access token
  client.getAccessToken(
      oauthSettings.requestToken
    , oauthSettings.requestTokenSecret
    , verifier
    , function (err, token, secret) {
        if (err) {
          // Take action
          return;
        }

        oauthSettings.accessToken = token;
        oauthSettings.accessTokenSecret = secret;

        res.redirect('/stats');
      }
  );
});

// Display some stats
app.get('/stats', function (req, res) {
  client = new Fitbit(
      config.CONSUMER_KEY
    , config.CONSUMER_SECRET
    , { // Now set with access tokens
          accessToken: req.session.oauth.accessToken
        , accessTokenSecret: req.session.oauth.accessTokenSecret
        , unitMeasure: 'en_GB'
      }
  );

  // Fetch todays activities
  client.getActivities(function (err, activities) {
    if (err) {
      // Take action
      return;
    }

    // `activities` is a Resource model
    res.send('Total steps today: ' + activities.steps());
  });
});

node-fitbit's People

Contributors

p-m-p avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-fitbit's Issues

Failing to load node-oauth

I'm trying to install this package and get this error

Charless-MacBook-Air% npm install fitbit
npm WARN package.json [email protected] No description
npm WARN package.json [email protected] No README data
npm http GET https://registry.npmjs.org/fitbit
npm http 304 https://registry.npmjs.org/fitbit
npm http GET https://registry.npmjs.org/lodash
npm http 304 https://registry.npmjs.org/lodash
npm ERR! git clone git://github.com/p-m-p/node-oauth Cloning into bare repository '/Users/majora/.npm/_git-remotes/git-github-com-p-m-p-node-oauth-efba15d2'...
npm ERR! git clone git://github.com/p-m-p/node-oauth fatal: unable to connect to github.com:
npm ERR! git clone git://github.com/p-m-p/node-oauth github.com[0: 192.30.252.130]: errno=Operation timed out
npm ERR! Error: Command failed: Cloning into bare repository '/Users/majora/.npm/_git-remotes/git-github-com-p-m-p-node-oauth-efba15d2'...
npm ERR! fatal: unable to connect to github.com:
npm ERR! github.com[0: 192.30.252.130]: errno=Operation timed out
npm ERR!
npm ERR!
npm ERR!     at ChildProcess.exithandler (child_process.js:647:15)
npm ERR!     at ChildProcess.EventEmitter.emit (events.js:98:17)
npm ERR!     at maybeClose (child_process.js:753:16)
npm ERR!     at Socket.<anonymous> (child_process.js:966:11)
npm ERR!     at Socket.EventEmitter.emit (events.js:95:17)
npm ERR!     at Pipe.close (net.js:465:12)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>

npm ERR! System Darwin 13.3.0
npm ERR! command "/usr/local/opt/nvm/v0.10.28/bin/node" "/usr/local/opt/nvm/v0.10.28/bin/npm" "install" "fitbit"
npm ERR! cwd /Users/majora/Code/GetSomeSleep
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.9
npm ERR! code 128
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/majora/Code/GetSomeSleep/npm-debug.log
npm ERR! not ok code 0

I noticed you are using a custom fork of OAuth, is this necessary?

user id details

Hi Support,

I am not getting the user id after hitting the callback function. I am getting only the access token and the token secret. Please let me know how can i get it and where the function has been written in the library file

Please make this one change!

Please change the following line in the /lib/fitbit.js:

var OAuth = require('OAuth')

to

var OAuth = require('oauth')

It works fine on Windows but on Unix/Linux based systems it causes an error. I changed this line and now my app is running fine on my AWS EC2 instance.

Regards

Matloob

Typos in README sample

  1. You're missing an additional }); to close up app.get
  2. Consider adding express and connect as devDependencies in package.json.

Invalid signature or token

Thanks for the module, however I'm having problems with authentication. I'm running v0.0.6.

I have the users access token, secret and am trying to run the getActivities request as per the demo, but getting an "Invalid signature or token" error from Fitbit.

Anything you've encountered before?

Heart Rate Tracking

HI,
Anyone can give me idea to write the resource for the heart rate. Currently we dont have the resource for the heart-rate.

Unable to install via NPM

When trying to install via npm i receive the following error.

npm install
npm ERR! install Couldn't read dependencies
npm ERR! Error: Invalid name: "VirtMatt-Fitbit/PB"
npm ERR!     at ensureValidName (/usr/lib/node_modules/normalize-package-data/lib/fixer.js:281:15)
npm ERR!     at Object.module.exports.fixNameField (/usr/lib/node_modules/normalize-package-data/lib/fixer.js:196:5)
npm ERR!     at /usr/lib/node_modules/normalize-package-data/lib/normalize.js:29:38
npm ERR!     at Array.forEach (native)
npm ERR!     at normalize (/usr/lib/node_modules/normalize-package-data/lib/normalize.js:28:15)
npm ERR!     at final (/usr/lib/node_modules/read-package-json/read-json.js:310:33)
npm ERR!     at then (/usr/lib/node_modules/read-package-json/read-json.js:124:33)
npm ERR!     at /usr/lib/node_modules/read-package-json/read-json.js:284:48
npm ERR!     at fs.js:208:20
npm ERR!     at OpenReq.Req.done (/usr/lib/node_modules/graceful-fs/graceful-fs.js:135:5)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

npm ERR! System Linux 3.10.0-229.4.2.el7.x86_64
npm ERR! command "node" "/usr/bin/npm" "install"
npm ERR! cwd /home/setkeh/Dev/fitbit
npm ERR! node -v v0.10.36
npm ERR! npm -v 1.3.6
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/setkeh/Dev/fitbit/npm-debug.log
npm ERR! not ok code 0

Any idea's ??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.