File tree 3 files changed +16
-12
lines changed
3 files changed +16
-12
lines changed Original file line number Diff line number Diff line change 1
1
# sdk-oauth
2
2
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.
5
7
6
8
## Usage
7
9
8
10
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:
10
13
11
14
- OAuth 2.0 Application Type: ** Server**
12
15
- Callback URL:
@@ -15,5 +18,10 @@ Web API to query sleep data.
15
18
2 . Enter your ** OAuth 2.0 Client ID** and ** Client Secret** into
16
19
` settings/index.jsx `
17
20
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
+
18
26
Read more in the [ Reference
19
27
documentation] ( https://dev.fitbit.com/reference/#overview ) .
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { settingsStorage } from "settings";
5
5
function fetchSleepData ( accessToken ) {
6
6
let todayDate = new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) ; //YYYY-MM-DD
7
7
8
+ // Sleep API docs - https://dev.fitbit.com/reference/web-api/sleep/
8
9
fetch ( `https://api.fitbit.com/1.2/user/-/sleep/date/${ todayDate } .json` , {
9
10
method : "GET" ,
10
11
headers : {
@@ -18,18 +19,13 @@ function fetchSleepData(accessToken) {
18
19
let myData = {
19
20
totalMinutesAsleep : data . summary . totalMinutesAsleep
20
21
}
21
- sendVal ( myData ) ;
22
+ if ( messaging . peerSocket . readyState === messaging . peerSocket . OPEN ) {
23
+ messaging . peerSocket . send ( myData ) ;
24
+ }
22
25
} )
23
26
. catch ( err => console . log ( '[FETCH]: ' + err ) ) ;
24
27
}
25
28
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
-
33
29
// A user changes Settings
34
30
settingsStorage . onchange = evt => {
35
31
if ( evt . key === "oauth" ) {
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ function mySettings(props) {
12
12
requestTokenUrl = "https://api.fitbit.com/oauth2/token"
13
13
clientId = "XXXXXXXXXX"
14
14
clientSecret = "XXXXXXXXXX"
15
- scope = "profile sleep"
15
+ scope = "sleep"
16
16
/>
17
17
</ Section >
18
18
</ Page >
You can’t perform that action at this time.
0 commit comments