Skip to content

Commit

Permalink
Merge pull request #23 from jmdiego/master
Browse files Browse the repository at this point in the history
Overall update
  • Loading branch information
jmdiego committed Jan 13, 2018
2 parents 179b84c + 1ea1b99 commit 7daf379
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 223 deletions.
36 changes: 19 additions & 17 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
// initialize the express application
var express = require("express"),
app = express();
const express = require("express");
const app = express();

// initialize the Fitbit API client
var FitbitApiClient = require("fitbit-node"),
client = new FitbitApiClient("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
const FitbitApiClient = require("fitbit-node");
const client = new FitbitApiClient({
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET",
apiVersion: '1.2' // 1.2 is the default
});

// redirect the user to the Fitbit authorization page
app.get("/authorize", function (req, res) {
// request access to the user's activity, heartrate, location, nutrion, profile, settings, sleep, social, and weight scopes
res.redirect(client.getAuthorizeUrl('activity heartrate location nutrition profile settings sleep social weight', 'YOUR_CALLBACK_URL'));
app.get("/authorize", (req, res) => {
// request access to the user's activity, heartrate, location, nutrion, profile, settings, sleep, social, and weight scopes
res.redirect(client.getAuthorizeUrl('activity heartrate location nutrition profile settings sleep social weight', 'YOUR_CALLBACK_URL'));
});

// handle the callback from the Fitbit authorization flow
app.get("/callback", function (req, res) {
// exchange the authorization code we just received for an access token
client.getAccessToken(req.query.code, 'YOUR_CALLBACK_URL').then(function (result) {
// use the access token to fetch the user's profile information
client.get("/profile.json", result.access_token).then(function (results) {
res.send(results[0]);
});
}).catch(function (error) {
res.send(error);
});
app.get("/callback", (req, res) => {
// exchange the authorization code we just received for an access token
client.getAccessToken(req.query.code, 'YOUR_CALLBACK_URL').then(result => {
// use the access token to fetch the user's profile information
client.get("/profile.json", result.access_token).then(results => {
res.send(results[0]);
});
}).catch(res.send);
});

// launch the server
Expand Down
Loading

0 comments on commit 7daf379

Please sign in to comment.