Updated, AndroidManifest still not working right
This commit is contained in:
parent
28dd214897
commit
519dfff2bc
1 changed files with 4 additions and 37 deletions
|
@ -18,10 +18,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
private const string _consumerSecret = "69307b9f332caf9946ef4e23cabde2e4";
|
private const string _consumerSecret = "69307b9f332caf9946ef4e23cabde2e4";
|
||||||
private const string _clientId = "22CX4L";
|
private const string _clientId = "22CX4L";
|
||||||
private const string _callbackURL = "http://localhost/callback";
|
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 CustomAndroidScheme = "mocha://";
|
||||||
|
|
||||||
private const string _tokenUrl = "https://api.fitbit.com/oauth2/token";
|
private const string _tokenUrl = "https://api.fitbit.com/oauth2/token";
|
||||||
|
@ -47,7 +43,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
private OAuth2AccessToken _oAuth2 = new OAuth2AccessToken();
|
private OAuth2AccessToken _oAuth2 = new OAuth2AccessToken();
|
||||||
public FitbitData _fitbitData = new FitbitData();
|
public FitbitData _fitbitData = new FitbitData();
|
||||||
|
|
||||||
//Debug String for Android
|
|
||||||
private string _statusMessage;
|
private string _statusMessage;
|
||||||
|
|
||||||
private string CallBackUrl
|
private string CallBackUrl
|
||||||
|
@ -79,19 +74,10 @@ namespace Assets.Scripts.Fitbit
|
||||||
{
|
{
|
||||||
_bFirstFire = false;
|
_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()
|
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"))
|
if (PlayerPrefs.HasKey("FitbitRefreshToken"))
|
||||||
{
|
{
|
||||||
|
@ -105,7 +91,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
}
|
}
|
||||||
public void UserAcceptOrDeny()
|
public void UserAcceptOrDeny()
|
||||||
{
|
{
|
||||||
//we don't have a refresh token so we gotta go through the whole auth process.
|
|
||||||
var url =
|
var url =
|
||||||
"https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=" + _clientId + "&prompt=login&redirect_uri=" +
|
"https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=" + _clientId + "&prompt=login&redirect_uri=" +
|
||||||
CallBackUrl +
|
CallBackUrl +
|
||||||
|
@ -125,7 +110,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
private void UseReturnCode()
|
private void UseReturnCode()
|
||||||
{
|
{
|
||||||
Debug.Log("return code isn't empty");
|
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 plainTextBytes = System.Text.Encoding.UTF8.GetBytes(_clientId + ":" + _consumerSecret);
|
||||||
var encoded = Convert.ToBase64String(plainTextBytes);
|
var encoded = Convert.ToBase64String(plainTextBytes);
|
||||||
|
|
||||||
|
@ -141,7 +125,7 @@ namespace Assets.Scripts.Fitbit
|
||||||
_wwwRequest = new WWW(_tokenUrl, form.data, headers);
|
_wwwRequest = new WWW(_tokenUrl, form.data, headers);
|
||||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||||
|
|
||||||
//DIRTY DIRTY HACK
|
|
||||||
while (!_wwwRequest.isDone)
|
while (!_wwwRequest.isDone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -152,8 +136,7 @@ namespace Assets.Scripts.Fitbit
|
||||||
var parsed = new JSONObject(_wwwRequest.text);
|
var parsed = new JSONObject(_wwwRequest.text);
|
||||||
ParseAccessToken(parsed);
|
ParseAccessToken(parsed);
|
||||||
Debug.Log("\nParsed Token: " + _oAuth2.Token);
|
Debug.Log("\nParsed Token: " + _oAuth2.Token);
|
||||||
|
|
||||||
//now that we have the Auth Token, Lets use it and get data.
|
|
||||||
GetAllData();
|
GetAllData();
|
||||||
Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps);
|
Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps);
|
||||||
_bGotTheData = true;
|
_bGotTheData = true;
|
||||||
|
@ -174,14 +157,12 @@ namespace Assets.Scripts.Fitbit
|
||||||
|
|
||||||
_wwwRequest = new WWW(_tokenUrl, form.data, headers);
|
_wwwRequest = new WWW(_tokenUrl, form.data, headers);
|
||||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||||
//DIRTY DIRTY HACK
|
|
||||||
while (!_wwwRequest.isDone)
|
while (!_wwwRequest.isDone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log("RefreshToken wwwText: " + _wwwRequest.text);
|
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))
|
if (!String.IsNullOrEmpty(_wwwRequest.error))
|
||||||
{
|
{
|
||||||
PlayerPrefs.DeleteKey("FitbitRefreshToken");
|
PlayerPrefs.DeleteKey("FitbitRefreshToken");
|
||||||
|
@ -192,7 +173,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Log("Using the Auth Token (UseRefreshToken)");
|
Debug.Log("Using the Auth Token (UseRefreshToken)");
|
||||||
//no errors so parse the accessToken and update everything :)
|
|
||||||
var parsed = new JSONObject(_wwwRequest.text);
|
var parsed = new JSONObject(_wwwRequest.text);
|
||||||
ParseAccessToken(parsed);
|
ParseAccessToken(parsed);
|
||||||
GetAllData();
|
GetAllData();
|
||||||
|
@ -203,8 +183,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(code))
|
if (string.IsNullOrEmpty(code))
|
||||||
return;
|
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);
|
_returnCode = code.Substring(CustomAndroidScheme.Length + 6);
|
||||||
Debug.Log("Return Code is: " + _returnCode);
|
Debug.Log("Return Code is: " + _returnCode);
|
||||||
|
|
||||||
|
@ -228,8 +206,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
GetProfileData();
|
GetProfileData();
|
||||||
GetAllRelevantData();
|
GetAllRelevantData();
|
||||||
BuildProfile();
|
BuildProfile();
|
||||||
|
|
||||||
//make sure the loading screen is open and change message
|
|
||||||
_fitbitData.LastSyncTime = DateTime.Now.ToUniversalTime();
|
_fitbitData.LastSyncTime = DateTime.Now.ToUniversalTime();
|
||||||
Debug.Log("LastSyncTime: " + DateTime.Now.ToUniversalTime().ToString("g"));
|
Debug.Log("LastSyncTime: " + DateTime.Now.ToUniversalTime().ToString("g"));
|
||||||
}
|
}
|
||||||
|
@ -254,7 +230,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
Debug.Log("Doing GET Request");
|
Debug.Log("Doing GET Request");
|
||||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||||
|
|
||||||
//DIRTY DIRTY HACK
|
|
||||||
while (!_wwwRequest.isDone)
|
while (!_wwwRequest.isDone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -265,7 +240,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
|
|
||||||
private void GetCalories()
|
private void GetCalories()
|
||||||
{
|
{
|
||||||
//time for Getting Dataz
|
|
||||||
var headers = new Dictionary<string, string>();
|
var headers = new Dictionary<string, string>();
|
||||||
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
||||||
|
|
||||||
|
@ -274,7 +248,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
Debug.Log("Doing Calories GET Request");
|
Debug.Log("Doing Calories GET Request");
|
||||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||||
|
|
||||||
//DIRTY DIRTY HACK
|
|
||||||
while (!_wwwRequest.isDone)
|
while (!_wwwRequest.isDone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -283,7 +256,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
|
|
||||||
private void GetDistance()
|
private void GetDistance()
|
||||||
{
|
{
|
||||||
//time for Getting Dataz
|
|
||||||
var headers = new Dictionary<string, string>();
|
var headers = new Dictionary<string, string>();
|
||||||
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
||||||
|
|
||||||
|
@ -292,7 +264,7 @@ namespace Assets.Scripts.Fitbit
|
||||||
Debug.Log("Doing Distance GET Request");
|
Debug.Log("Doing Distance GET Request");
|
||||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||||
|
|
||||||
//DIRTY DIRTY HACK
|
|
||||||
while (!_wwwRequest.isDone)
|
while (!_wwwRequest.isDone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -302,7 +274,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
|
|
||||||
private void GetSteps()
|
private void GetSteps()
|
||||||
{
|
{
|
||||||
//time for Getting Dataz
|
|
||||||
var headers = new Dictionary<string, string>();
|
var headers = new Dictionary<string, string>();
|
||||||
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
||||||
|
|
||||||
|
@ -311,7 +282,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
Debug.Log("Doing Steps GET Request");
|
Debug.Log("Doing Steps GET Request");
|
||||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||||
|
|
||||||
//DIRTY DIRTY HACK
|
|
||||||
while (!_wwwRequest.isDone)
|
while (!_wwwRequest.isDone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -321,7 +291,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
|
|
||||||
private void GetSleep()
|
private void GetSleep()
|
||||||
{
|
{
|
||||||
//time for Getting Dataz
|
|
||||||
var headers = new Dictionary<string, string>();
|
var headers = new Dictionary<string, string>();
|
||||||
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
||||||
|
|
||||||
|
@ -504,8 +473,6 @@ namespace Assets.Scripts.Fitbit
|
||||||
Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps);
|
Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps);
|
||||||
Debug.Log(www.text);
|
Debug.Log(www.text);
|
||||||
Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps);
|
Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps);
|
||||||
//Debug.Log("WWW Ok!: " + www.text);
|
|
||||||
// _accessToken = www.responseHeaders["access_token"];
|
|
||||||
}
|
}
|
||||||
if (www.error != null)
|
if (www.error != null)
|
||||||
{
|
{
|
||||||
|
|
Reference in a new issue