Skip to content

Commit 7daf379

Browse files
authored
Merge pull request #23 from jmdiego/master
Overall update
2 parents 179b84c + 1ea1b99 commit 7daf379

File tree

4 files changed

+210
-223
lines changed

4 files changed

+210
-223
lines changed

example.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
// initialize the express application
2-
var express = require("express"),
3-
app = express();
2+
const express = require("express");
3+
const app = express();
44

55
// initialize the Fitbit API client
6-
var FitbitApiClient = require("fitbit-node"),
7-
client = new FitbitApiClient("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
6+
const FitbitApiClient = require("fitbit-node");
7+
const client = new FitbitApiClient({
8+
clientId: "YOUR_CLIENT_ID",
9+
clientSecret: "YOUR_CLIENT_SECRET",
10+
apiVersion: '1.2' // 1.2 is the default
11+
});
812

913
// redirect the user to the Fitbit authorization page
10-
app.get("/authorize", function (req, res) {
11-
// request access to the user's activity, heartrate, location, nutrion, profile, settings, sleep, social, and weight scopes
12-
res.redirect(client.getAuthorizeUrl('activity heartrate location nutrition profile settings sleep social weight', 'YOUR_CALLBACK_URL'));
14+
app.get("/authorize", (req, res) => {
15+
// request access to the user's activity, heartrate, location, nutrion, profile, settings, sleep, social, and weight scopes
16+
res.redirect(client.getAuthorizeUrl('activity heartrate location nutrition profile settings sleep social weight', 'YOUR_CALLBACK_URL'));
1317
});
1418

1519
// handle the callback from the Fitbit authorization flow
16-
app.get("/callback", function (req, res) {
17-
// exchange the authorization code we just received for an access token
18-
client.getAccessToken(req.query.code, 'YOUR_CALLBACK_URL').then(function (result) {
19-
// use the access token to fetch the user's profile information
20-
client.get("/profile.json", result.access_token).then(function (results) {
21-
res.send(results[0]);
22-
});
23-
}).catch(function (error) {
24-
res.send(error);
25-
});
20+
app.get("/callback", (req, res) => {
21+
// exchange the authorization code we just received for an access token
22+
client.getAccessToken(req.query.code, 'YOUR_CALLBACK_URL').then(result => {
23+
// use the access token to fetch the user's profile information
24+
client.get("/profile.json", result.access_token).then(results => {
25+
res.send(results[0]);
26+
});
27+
}).catch(res.send);
2628
});
2729

2830
// launch the server

0 commit comments

Comments
 (0)