Closed patriksharma closed 3 years ago
Can you please log any of the index?
@aboveyunhai @enestatli Please see explained version of the issue. Let me post everything so you can understand what is the problem or issue here.
First I have declared a scopes:
const options = {
scopes: [
Scopes.FITNESS_ACTIVITY_READ,
Scopes.FITNESS_ACTIVITY_WRITE,
Scopes.FITNESS_BODY_READ,
Scopes.FITNESS_BODY_WRITE,
Scopes.FITNESS_SLEEP_READ,
],
}
getSleepdata()
{
let opt = {
startDate: "2021-04-01T00:00:17.971Z", // required
endDate: new Date().toISOString(), // required
};
GoogleFit.getSleepSamples(opt).then((res)=> {
console.log("sleepdata",res)
});
}
Now when I call this function I receive this as output log. You will see its not giving me data as required (date, steps etc). It simply showing be [object]
Where Sleep {success:true} is value of Authorized method.
GoogleFit.authorize(options)
.then(authResult => {
if (authResult.success) {
console.log("Sleep",authResult);
} else {
console.log("Sleep",authResult.message);
//dispatch("AUTH_DENIED", authResult.message);
}
})
.catch(() => {
})
@patriksharma This is the expected behavior if your log does not handle nested data structures. Object
here refers to the type
of content instead of the content itself. You need to iterate through the array to check each element by yourself.
When in doubt, try some codes out.
It seems like you don't understand some JavaScript stuffs, and heavily rely on log()
info. so I highly suggest you search your problem or ask it in StackOverflow first. This question technically has nothing to do with this package.
To give you an idea: https://stackoverflow.com/questions/10729276/how-can-i-get-the-full-object-in-node-jss-console-log-rather-than-object
@aboveyunhai Thanks a lot for sharing that link, It looks helpful. Yes I'm new to react native and worked only on Swift.
thanks for helping out here.
I think we both understand the issue but the point you missing is the logged array holds the all sleep data starting from startDate: "2021-04-01T00:00:17.971Z" until now. So you need to filter thorugh that array and check if data.source === 'com.whatyouneed_steps' and map to the filtered list to get the sleep,steps or whatever you need values.
console.log(JSON.stringify(myObject, null, 4));
yes worked with this
[
{
"source": "com.google.android.gms:estimated_steps",
"steps": [
{
"date": "2021-04-15",
"value": 27
},
{
"date": "2021-04-16",
"value": 3720
},
{
"date": "2021-04-17",
"value": 10415
},
{
"date": "2021-04-19",
"value": 4204
},
{
"date": "2021-04-20",
"value": 473
},
{
"date": "2021-04-21",
"value": 118
}
],
I have implemented a library, Authorized is true but when I try to get Sleep data or steps data I'm getting object array and no instructions how to decode it.
"granularity": [[Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object]],
No idea how to decode that object to get real values