Skip to content

Commit b4f3456

Browse files
author
Jon Barlow
committed
Thomas' feedback
1 parent b088013 commit b4f3456

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# sdk-oauth
22

3-
A sample application which uses the Settings API OAuth component, and the Fitbit
4-
Web API to query sleep data.
3+
A sample application which uses the Settings API [OAuth
4+
component](https://dev.fitbit.com/reference/settings-api/#oauth-button), and the
5+
[Fitbit Web API](https://dev.fitbit.com/reference/web-api/quickstart/) to query
6+
sleep data.
57

68
## Usage
79

810
1. You must first register a Web Application on
9-
[dev.fitbit.com](https://dev.fitbit.com/apps/new).
11+
[dev.fitbit.com](https://dev.fitbit.com/apps/new) to get an OAuth ID and
12+
secret. Configure the application as:
1013

1114
- OAuth 2.0 Application Type: **Server**
1215
- Callback URL:
@@ -15,5 +18,10 @@ Web API to query sleep data.
1518
2. Enter your **OAuth 2.0 Client ID** and **Client Secret** into
1619
`settings/index.jsx`
1720

21+
3. After installing the project from Fitbit Studio, you need to login to the
22+
Fitbit Web API using the settings page within the Fitbit mobile application.
23+
24+
***Fitbit mobile app > Ionic > Developer menu > your app > Settings***
25+
1826
Read more in the [Reference
1927
documentation](https://dev.fitbit.com/reference/#overview).

companion/index.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { settingsStorage } from "settings";
55
function fetchSleepData(accessToken) {
66
let todayDate = new Date().toISOString().slice(0,10); //YYYY-MM-DD
77

8+
// Sleep API docs - https://dev.fitbit.com/reference/web-api/sleep/
89
fetch(`https://api.fitbit.com/1.2/user/-/sleep/date/${todayDate}.json`, {
910
method: "GET",
1011
headers: {
@@ -18,18 +19,13 @@ function fetchSleepData(accessToken) {
1819
let myData = {
1920
totalMinutesAsleep: data.summary.totalMinutesAsleep
2021
}
21-
sendVal(myData);
22+
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
23+
messaging.peerSocket.send(myData);
24+
}
2225
})
2326
.catch(err => console.log('[FETCH]: ' + err));
2427
}
2528

26-
// Send data to the device
27-
function sendVal(data) {
28-
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
29-
messaging.peerSocket.send(data);
30-
}
31-
}
32-
3329
// A user changes Settings
3430
settingsStorage.onchange = evt => {
3531
if (evt.key === "oauth") {

settings/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function mySettings(props) {
1212
requestTokenUrl="https://api.fitbit.com/oauth2/token"
1313
clientId="XXXXXXXXXX"
1414
clientSecret="XXXXXXXXXX"
15-
scope="profile sleep"
15+
scope="sleep"
1616
/>
1717
</Section>
1818
</Page>

0 commit comments

Comments
 (0)