I’ve already registered Google OAuth 2.0 Client ID to enable the Fitness API and added cordova-plugin-health plugin following the Ionic Health document guideline too.
When I launch android app and access the [distance, nutrition … ] datatype, happened the following error. Do I need any additional process or code?
Any comment or guidance would be appreciated.
Error logs:
/health-health-module.js:150 platform ready!
/health-health-module.js:163 avaiable:true
/health-health-module.js:165 Already Authorised
/health-health-module.js:183 com.google.android.gms.common.api.ApiException: 4: The user must be signed in to make this API call.
/health-health-module.js:175 error User cancelled
==========================================
// my typescript code (Angular):
constructor(private health: Health, private platform: Platform) { }
ngOnInit() {
this.checkPlatformReady();
}
async checkPlatformReady() {
const ready = !!await this.platform.ready();
if (ready) {
console.log(‘platform ready!’)
}
this.health.isAvailable().then((available:boolean) => {
console.log('avaiable:' + available);
if (this.health.isAuthorized(["steps"])) {
console.log("Already Authorised");
this.health.requestAuthorization([ // **** Here is error happened... ***** //
"distance",
"nutrition",
{
read: ["steps", "height", "weight"],
write: ["height", "weight"],
},
])
.then((res) => console.log("response " + res))
.catch((e) => console.log("error " + e));
this.health.queryAggregated({
startDate: new Date(new Date().getTime() - 3 * 24 * 60 * 60 * 1000),
endDate: new Date(), // now
dataType: 'steps',
bucket: 'day'
})
.then(res => console.log(res))
.catch(e => console.log(e));
} else {
this.health
.requestAuthorization([
"distance",
"nutrition",
{
read: ["steps"],
write: ["height", "weight"],
},
])
.then((res) => console.log(res))
.catch((e) => console.log(e));
}
})
.catch(e => console.log(e));
}