********************************************************************************************************** Fitbit2.0 Documentation - Tyler Hacker '16 Step by Step guide to using Fitbit2.0 All OAuth2.0 files were found at http://www.phpclasses.org/package/7700-PHP-Authorize-and-access-APIs-using-OAuth.html Manuel Lemos (author) was extremely helpful and willing to answer any questions regarding his class All class credit goes to Manuel. I simply change a few things and he did the rest. Appended Documentation- Thomas Wolf '17 *********************************************************************************************************** OAUTH2.0 Fitbit Application Set-up ******************************************** 1. Create Fitbit account and connect Fitbit device to account 2. Register App on Fitbit website (https://dev.fitbit.com/apps) 3. Set to Client, Browser, and Read/Write (really don't need write aspect) 4. Set callback URL to http://compsci02.snc.edu/cs460/20##/USERNAME/-------index.php For example: http://compsci02.snc.edu/cs460/2016/hacktw/Tyler_capstone_project/OAuth2/index.php 5. Record Client ID, Secret, and Redirect URL for later use OAUTH2.0 changes to files listed above Stressball1.1 Thomas Wolf **************************************************************** 1. index.php This file contains the calls to fitbit and api permissions. When you first run the index file comment out hearate from array $client->scope = 'activity sleep heartrate'; and comment out the api request success = $client->CallAPI( 'https://api.fitbit.com/1/user/-/activities/heart/date/today/1d/1min/time/'.date('H:i',strtotime('-20 minutes')).'/'.date('H:i',strtotime('now')).'.json', 'GET', array(), array('FailOnAccessError'=>true), $heartrate); 2. In order to get access to heart rate data you will need to contact the fitbit dev team by email, and request that your account and app have access to private information. They will ask you some questions on what the app is to be used for and who will be using your app. Once you have their permission change you settings from CLIENT TO PERSONAL 3. Uncomment out the api and you will have access to the heart data -TW OAUTH2.0 Files - http://www.phpclasses.org/package/7700-PHP-Authorize-and-access-APIs-using-OAuth.html ******************************************** Place these files in your compsci02.snc.edu/cs460/USERNAME/....... (Literally copy and paste these files to your destination) 1. index.php (runs the acual code-Main-and transfers data into easy text file) 2. http.php (Connecting to HTTP and Fitbit data) 3. oauth_client.php (Process of OAuth) 4. oauth_configuration.json (composer file) OAUTH2.0 Changes to Files listed above ^ ********************************************* 1. index.php Redirect uri : Need to change to your file location (example given in file) Client_id : Enter new client id Client_secret : Enter new secret API Permissions : May need to change code for scope and $success in third 'if' statement Scopes can be found here: https://dev.fitbit.com/docs/oauth2/ More scopes = more $success statements //Log in message didn't display for me if OAuth successful, maybe it will for you 2. oauth.client.php var $log_file_name : Needs to be changed to a blank text file Must be in same location as index.php and other OAuth files OAUTH2.0 OTHER FILES TO ADD ********************************************* Place these other files in the same location as the files listed above 1. correctdata.txt (actual file that app reads off of) 2. OA2data.txt (all OAuth process and data are put in here. Index.php parses this and places relevant data in correctdata.txt) How OAuth2.0 works in Stressball App - Tyler ********************************************* 1. In Health.java, StepsNotifyService.java, and SleepNotifyService.java, connectTask/LconnectTask runs Oauth2.0 in the background. When the file is run, the user is authorized and the Fitbit data is outputted to a text file that is designated in oauth.client.php (which you need to change, see above). This data is outputted as a JSON, so it needs to be manipulated. Unfortunately, I was not able to complete that so hopefully you will have better luck. Currently, I am accessing just a random text file that contains values in a specific order, the same order it would appear if I had figured out JSON. -TH How OAuth2 works in Stresball1.1 App-Thomas ******************************************** 1.) In heartservice.java oAuth2 is called every 20 min to update the fitbit data. This can also be done manually throught the connect to fitbit button on the home screen incase the service is not working. The service will continue to run the background even if the phone is turned off so the data will always be updating. When oAuth is the data is parsed into three sperate json files. Sleep.json heart.json and steps.json. Once the files have been updated the information they contain will then fill the arrays for the heart data section of the app. So the user can visually see the data. -TW