react native android,在尝试获取firebase消息传递设备令牌时获得FIS_AUTH_ERROR

koaltpgm  于 2023-04-07  发布在  React
关注(0)|答案(2)|浏览(149)

我尝试使用react native base messaging和react native push notifications library获取Android设备令牌来发送推送通知:
我在AndroidManifest.xml中添加了配置:

...
   <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <!-- < Only if you are using GCM or localNotificationSchedule() > -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <permission
        android:name="${applicationId}.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
    <!-- < Only if you are using GCM or localNotificationSchedule() > -->
...

在我的App.js

// ----- COMPONENT DID MOUNT ---- //
  async componentDidMount() {
    // ====================================================== //
    // ====================================================== //
    // ====================================================== //
    const granted = messaging().requestPermission();

    if (granted) {
      console.log('User granted messaging permissions!');
      // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
      firebase
        .messaging()
        .getToken()
        .then((fcmToken) => {
          if (fcmToken) {
            // user has a device token
            console.log('-------- FCM TOKEN -------');
            console.log(fcmToken);
            console.log(JSON.stringify(fcmToken));
            this._setItem(fcmToken);
          } else {
            // user doesn't have a device token yet
            console.log('error');
          }
        });
      // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
    } else {
      console.log('User declined messaging permissions :(');
    }
    // ====================================================== //
    // ====================================================== //
    // ====================================================== //
  }
  // ----- FIN COMPONENT DID MOUNT ---- //

我得到了:
可能的未处理Promise拒绝(id:0):
错误:[消息传递/未知] FIS_AUTH_ERROR
NativeFirebaseError:[消息传递/未知] FIS_AUTH_ERROR

djmepvbi

djmepvbi1#

Google Cloud Console中,确保google-services.json中的API密钥包含以下权限:

  • Firebase Cloud Messaging API
  • Firebase安装API
w3nuxt5m

w3nuxt5m2#

我通过再次下载google-services.json文件并将其替换为旧文件来修复它。

相关问题