Quantcast
Channel: Questions in topic: "httpwebrequest"
Viewing all articles
Browse latest Browse all 190

Why do I get Parse error (code 400) from Google Ftiness API in Unity?

$
0
0
I am trying to read steps count from GoogleFitness API in Unity application. First I go to Google's OAuthPlayground, authorize the fitness api and copy the access token. In Unity I have a scene with text field and a button. I paste the access token to the textfield and click the button. On Button click the method GetStepsResponse is being called with input field's content as a param. The logic behind: public void GetStepsResponse(string idToken) { StartCoroutine(SendPostCoroutine(idToken)); } IEnumerator SendPostCoroutine(string accessToken) { string request = "https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate"; request = string.Concat(request, "?access_token=", accessToken); string body = "{ \"aggregateBy\": [{ \"dataTypeName\": \"com.google.step_count.delta\", \"dataSourceId\": \"derived:com.google.step_count.delta:com.google.android.gms:estimated_steps\" }], \"bucketByTime\": { \"durationMillis\": 86400000 }, // This is 24 hours \"startTimeMillis\": 1577059200000, //start time \"endTimeMillis\": 1577577600000// End Time}"; UnityWebRequest webRequest = UnityWebRequest.Post(request, body); webRequest.SetRequestHeader("Content-type", "application/json"); yield return webRequest.SendWebRequest(); Debug.Log(webRequest.downloadHandler.text); } as a response I get: { "error": { "errors": [ { "domain": "global", "reason": "parseError", "message": "Parse Error" } ], "code": 400, "message": "Parse Error" } } I tried the same request with same body and headers here: https://apitester.com/ and I got a proper response with steps count for every day from given range. What I am missing?

Viewing all articles
Browse latest Browse all 190

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>