Skip to content

Commit

Permalink
Configurable api version, updated dependencies, updated OAuth usage a…
Browse files Browse the repository at this point in the history
…nd code syntax update to use ES6 feats
  • Loading branch information
jmdiego committed Jan 12, 2018
1 parent 179b84c commit 1ea1b99
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 1ea1b99

Please sign in to comment.