Firebase Android FCM INVALID_SENDER尝试获取令牌时



我创建了一个google-services.json文件并添加到我的android项目中,但当我试图获得令牌时,我收到了这个异常:

{
Java.IO.IOException: java.util.concurrent.ExecutionException: java.io.IOException: INVALID_SENDER ---> Java.Util.Concurrent.ExecutionException: java.io.IOException: INVALID_SENDER ---> Java.IO.IOException: INVALID_SENDER
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at VTInRoomApp.Droid.XamarinForms.MainActivityXam.OnComplete (Android.Gms.Tasks.Task task) [0x00039] in T:WorkVTDevMobileXamarinVTInRoomAppVTInRoomAppVTInRoomApp.AndroidXamarinFormsMainActivityXam.cs:157 
--- End of managed Java.IO.IOException stack trace ---
java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: INVALID_SENDER
at com.google.firebase.messaging.FirebaseMessaging.blockingGetToken(com.google.firebase:firebase-messaging@@22.0.0:14)
at com.google.firebase.messaging.FirebaseMessaging.lambda$getToken$2$FirebaseMessaging(com.google.firebase:firebase-messaging@@22.0.0:1)
at com.google.firebase.messaging.FirebaseMessaging$$Lambda$3.run(com.google.firebase:firebase-messaging@@22.0.0)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@17.6.0:2)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.util.concurrent.ExecutionException: java.io.IOException: INVALID_SENDER
at com.google.android.gms.tasks.Tasks.zza(com.google.android.gms:play-services-tasks@@17.2.1:5)
at com.google.android.gms.tasks.Tasks.await(com.google.android.gms:play-services-tasks@@17.2.1:8)
at com.google.firebase.messaging.FirebaseMessaging.blockingGetToken(com.google.firebase:firebase-messaging@@22.0.0:10)
... 9 more
Caused by: java.io.IOException: INVALID_SENDER
at com.google.firebase.messaging.GmsRpc.handleResponse(com.google.firebase:firebase-messaging@@22.0.0:7)
at com.google.firebase.messaging.GmsRpc.lambda$extractResponseWhenComplete$0$GmsRpc(com.google.firebase:firebase-messaging@@22.0.0:1)
at com.google.firebase.messaging.GmsRpc$$Lambda$1.then(com.google.firebase:firebase-messaging@@22.0.0)
at com.google.android.gms.tasks.zzc.run(com.google.android.gms:play-services-tasks@@17.2.1:3)
at com.google.firebase.messaging.GmsRpc$$Lambda$0.execute(com.google.firebase:firebase-messaging@@22.0.0)
at com.google.android.gms.tasks.zzd.zza(com.google.android.gms:play-services-tasks@@17.2.1:1)
at com.google.android.gms.tasks.zzr.zzb(com.google.android.gms:play-services-tasks@@17.2.1:5)
at com.google.android.gms.tasks.zzw.zza(com.google.android.gms:play-services-tasks@@17.2.1:3)
at com.google.android.gms.tasks.zzc.run(com.google.android.gms:play-services-tasks@@17.2.1:8)
at com.google.android.gms.cloudmessaging.zzz.execute(com.google.android.gms:play-services-cloud-messaging@@17.0.0)
at com.google.android.gms.tasks.zzd.zza(com.google.android.gms:play-services-tasks@@17.2.1:1)
at com.google.android.gms.tasks.zzr.zzb(com.google.android.gms:play-services-tasks@@17.2.1:5)
at com.google.android.gms.tasks.zzw.zza(com.google.android.gms:play-services-tasks@@17.2.1:3)
at com.google.android.gms.tasks.TaskCompletionSource.setResult(com.google.android.gms:play-services-tasks@@17.2.1:1)
at com.google.android.gms.cloudmessaging.zzp.zzd(com.google.android.gms:play-services-cloud-messaging@@17.0.0:3)
at com.google.android.gms.cloudmessaging.zzr.zza(com.google.android.gms:play-services-cloud-messaging@@17.0.0:2)
at com.google.android.gms.cloudmessaging.zzf.handleMessage(com.google.android.gms:play-services-cloud-messaging@@17.0.0:14)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6157)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
}

我在创建google-serves.json时是不是搞砸了,还是它在我的代码中?

非常感谢

通常,此错误是由json文件引起的。请查看以下信息进行确认。

  1. 检查是否已将文件复制到正确的项目文件夹中,并将"生成操作"设置为GoogleServicesJson
  2. 检查文件是否正确并与最新版本匹配下载了FCM中的google-services.json文件
  3. 检查您的项目中是否存在任何重复的google-services.json文件
  4. 请注意,当google-services.json添加到项目中(并且设置了GoogleServicesJson生成操作)时,生成过程会提取client IDAPI密钥,然后将这些凭据添加到位于obj/Debug/android/AndroidManifest.xml的合并/生成的AndroidManifest.xml中。如果你能确认一切都是正确的,删除bin和obj来清理和重建并重新打开项目可能会有所帮助
  5. 如果您仍然有这个问题,请按照MS文档中的步骤创建一个新项目。https://learn.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=windows

试试这个

FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "Fetching FCM registration token failed", task.getException());
return;
}
// Get new FCM registration token
String token = task.getResult();
// Log and toast
String msg = getString(R.string.msg_token_fmt, token);
Log.d(TAG, msg);
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});

相关内容

  • 没有找到相关文章

最新更新