From 519dfff2bcef5ea5ed96e1da69be5c9108fef30b Mon Sep 17 00:00:00 2001 From: Patrick Kitchens Date: Thu, 26 Apr 2018 06:36:49 -0500 Subject: [PATCH] Updated, AndroidManifest still not working right --- MoCha/Assets/Scripts/FitBitAPI.cs | 41 +++---------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/MoCha/Assets/Scripts/FitBitAPI.cs b/MoCha/Assets/Scripts/FitBitAPI.cs index 476f977..7563052 100644 --- a/MoCha/Assets/Scripts/FitBitAPI.cs +++ b/MoCha/Assets/Scripts/FitBitAPI.cs @@ -18,10 +18,6 @@ namespace Assets.Scripts.Fitbit private const string _consumerSecret = "69307b9f332caf9946ef4e23cabde2e4"; private const string _clientId = "22CX4L"; private const string _callbackURL = "http://localhost/callback"; - //If you're making an app for Android, fill in your custom scheme here from Fitbit - //if you don't know how to do the callback through a native browser on a mobile device - //http://technicalartistry.blogspot.ca/2016/01/fitbit-unity-oauth-2-and-native.html - //can probably help :) private const string CustomAndroidScheme = "mocha://"; private const string _tokenUrl = "https://api.fitbit.com/oauth2/token"; @@ -47,7 +43,6 @@ namespace Assets.Scripts.Fitbit private OAuth2AccessToken _oAuth2 = new OAuth2AccessToken(); public FitbitData _fitbitData = new FitbitData(); - //Debug String for Android private string _statusMessage; private string CallBackUrl @@ -79,19 +74,10 @@ namespace Assets.Scripts.Fitbit { _bFirstFire = false; } - GUI.Label(new Rect(10, 10, 500, 500), "Number Steps: " + _fitbitData.CurrentSteps); - - GUI.Label(new Rect(10, 20, 500, 500), "Calories: " + _fitbitData.CurrentCalories); - GUI.Label(new Rect(10, 40, 500, 500), "Distance Walked: " + _fitbitData.CurrentDistance); - GUI.Label(new Rect(10, 60, 500, 500), "Return Code " + _returnCode); } public void LoginToFitbit() { - //we'll check to see if we have the RefreshToken in PlayerPrefs or not. - //if we do, then we'll use the RefreshToken to get the data - //if not then we will just do the regular ask user to login to get data - //then save the tokens correctly. if (PlayerPrefs.HasKey("FitbitRefreshToken")) { @@ -105,7 +91,6 @@ namespace Assets.Scripts.Fitbit } public void UserAcceptOrDeny() { - //we don't have a refresh token so we gotta go through the whole auth process. var url = "https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=" + _clientId + "&prompt=login&redirect_uri=" + CallBackUrl + @@ -125,7 +110,6 @@ namespace Assets.Scripts.Fitbit private void UseReturnCode() { Debug.Log("return code isn't empty"); - //not empty means we put a code in var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(_clientId + ":" + _consumerSecret); var encoded = Convert.ToBase64String(plainTextBytes); @@ -141,7 +125,7 @@ namespace Assets.Scripts.Fitbit _wwwRequest = new WWW(_tokenUrl, form.data, headers); StartCoroutine(WaitForAccess(_wwwRequest)); - //DIRTY DIRTY HACK + while (!_wwwRequest.isDone) { } @@ -152,8 +136,7 @@ namespace Assets.Scripts.Fitbit var parsed = new JSONObject(_wwwRequest.text); ParseAccessToken(parsed); Debug.Log("\nParsed Token: " + _oAuth2.Token); - - //now that we have the Auth Token, Lets use it and get data. + GetAllData(); Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps); _bGotTheData = true; @@ -174,14 +157,12 @@ namespace Assets.Scripts.Fitbit _wwwRequest = new WWW(_tokenUrl, form.data, headers); StartCoroutine(WaitForAccess(_wwwRequest)); - //DIRTY DIRTY HACK + while (!_wwwRequest.isDone) { } Debug.Log("RefreshToken wwwText: " + _wwwRequest.text); - //check to see if it's errored or not - //we have an error and thus should just redo the Auth. if (!String.IsNullOrEmpty(_wwwRequest.error)) { PlayerPrefs.DeleteKey("FitbitRefreshToken"); @@ -192,7 +173,6 @@ namespace Assets.Scripts.Fitbit else { Debug.Log("Using the Auth Token (UseRefreshToken)"); - //no errors so parse the accessToken and update everything :) var parsed = new JSONObject(_wwwRequest.text); ParseAccessToken(parsed); GetAllData(); @@ -203,8 +183,6 @@ namespace Assets.Scripts.Fitbit { if (string.IsNullOrEmpty(code)) return; - //we passed the full URL so we'll have to extract the - //We will add 6 to the string lenght to account for "?code=" _returnCode = code.Substring(CustomAndroidScheme.Length + 6); Debug.Log("Return Code is: " + _returnCode); @@ -228,8 +206,6 @@ namespace Assets.Scripts.Fitbit GetProfileData(); GetAllRelevantData(); BuildProfile(); - - //make sure the loading screen is open and change message _fitbitData.LastSyncTime = DateTime.Now.ToUniversalTime(); Debug.Log("LastSyncTime: " + DateTime.Now.ToUniversalTime().ToString("g")); } @@ -254,7 +230,6 @@ namespace Assets.Scripts.Fitbit Debug.Log("Doing GET Request"); StartCoroutine(WaitForAccess(_wwwRequest)); - //DIRTY DIRTY HACK while (!_wwwRequest.isDone) { } @@ -265,7 +240,6 @@ namespace Assets.Scripts.Fitbit private void GetCalories() { - //time for Getting Dataz var headers = new Dictionary(); headers["Authorization"] = "Bearer " + _oAuth2.Token; @@ -274,7 +248,6 @@ namespace Assets.Scripts.Fitbit Debug.Log("Doing Calories GET Request"); StartCoroutine(WaitForAccess(_wwwRequest)); - //DIRTY DIRTY HACK while (!_wwwRequest.isDone) { } @@ -283,7 +256,6 @@ namespace Assets.Scripts.Fitbit private void GetDistance() { - //time for Getting Dataz var headers = new Dictionary(); headers["Authorization"] = "Bearer " + _oAuth2.Token; @@ -292,7 +264,7 @@ namespace Assets.Scripts.Fitbit Debug.Log("Doing Distance GET Request"); StartCoroutine(WaitForAccess(_wwwRequest)); - //DIRTY DIRTY HACK + while (!_wwwRequest.isDone) { } @@ -302,7 +274,6 @@ namespace Assets.Scripts.Fitbit private void GetSteps() { - //time for Getting Dataz var headers = new Dictionary(); headers["Authorization"] = "Bearer " + _oAuth2.Token; @@ -311,7 +282,6 @@ namespace Assets.Scripts.Fitbit Debug.Log("Doing Steps GET Request"); StartCoroutine(WaitForAccess(_wwwRequest)); - //DIRTY DIRTY HACK while (!_wwwRequest.isDone) { } @@ -321,7 +291,6 @@ namespace Assets.Scripts.Fitbit private void GetSleep() { - //time for Getting Dataz var headers = new Dictionary(); headers["Authorization"] = "Bearer " + _oAuth2.Token; @@ -504,8 +473,6 @@ namespace Assets.Scripts.Fitbit Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps); Debug.Log(www.text); Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps); - //Debug.Log("WWW Ok!: " + www.text); - // _accessToken = www.responseHeaders["access_token"]; } if (www.error != null) {