首页 > 解决方案 > 错误 5000:应用程序在使用 cordova-plugin-health 查询活动数据时需要用户的 OAuth 同意

问题描述

使用 Cordova Health Plugin 2.0.2 我们目前可以检索步骤数据,但在查询活动时收到 5000 错误。

已完成 OAuth 设置步骤以进行测试,并添加了用于读取和写入 Activity 数据的范围。使用的域也已经过验证。

活动请求是:

this.cordova.health().requestAuthorization(dataTypes, () => {
  this.cordova.health().isAuthorized(dataTypes, (authorized) => {
    if(authorized) {
      this.cordova.health().queryAggregated({
        startDate: startDate.toDate(),
        endDate: endDate.toDate(), // now
        dataType: 'activity',
        limit: 1000
      }, (data) => {

配置文件

    <preference name="android-minSdkVersion" value="22" />
    <preference name="android-maxSdkVersion" value="30" />
    <preference name="android-targetSdkVersion" value="29" />
    <preference name="android-compileSdkVersion" value="29" />
    <resource-file src="google-services.json" target="app/google-services.json" />
</platform>
<config-file parent="/*" target="config.xml">
    <preference name="GradlePluginGoogleServicesEnabled" value="true" />
    <preference name="GradlePluginGoogleServicesVersion" value="4.3.8" />
</config-file>
<config-file mode="merge" parent="/*" target="AndroidManifest.xml">
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-feature android:name="android.hardware.location.gps" 

android:required="false" />
    </config-file>
<preference name="AndroidXEnabled" value="true" />
  <plugin name="cordova-plugin-health" spec="^2.0.2">
        <variable name="HEALTH_READ_PERMISSION" value="App needs read access" />
        <variable name="HEALTH_WRITE_PERMISSION" value="App needs write access" />
    </plugin>

标签: androidcordova

解决方案


推荐阅读