Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 使用firebase发送推送通知-授权无效:找不到帐户错误_Asp.net Core_Firebase Cloud Messaging - Fatal编程技术网

Asp.net core 使用firebase发送推送通知-授权无效:找不到帐户错误

Asp.net core 使用firebase发送推送通知-授权无效:找不到帐户错误,asp.net-core,firebase-cloud-messaging,Asp.net Core,Firebase Cloud Messaging,我正在使用google firebase向我的移动应用程序发送推送通知。firebase控制台中添加了一个项目,这些项目创建了android和ios应用程序。我获取设备ID并将其保存在后端。当我想发送通知时,我只需要调用FirebaseMessaging var message = new Message(){Notification = notification, Token = device.Token}; try { string response = await Firebas

我正在使用google firebase向我的移动应用程序发送推送通知。firebase控制台中添加了一个项目,这些项目创建了android和ios应用程序。我获取设备ID并将其保存在后端。当我想发送通知时,我只需要调用FirebaseMessaging

var message = new Message(){Notification = notification, Token = device.Token};
    
try
{
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
}
catch (Exception ex)
{
}
Firebase被添加到Startup.cs中,如下所示

var googleCredential = Path.Combine("GoogleFirebaseCredentials.json");
var credential = GoogleCredential.FromFile(googleCredential);
            
FirebaseApp.Create(new AppOptions(){Credential = credential});
当我在本地运行服务器时,推送通知起作用,但当我发布服务器时,推送通知不起作用。我得到的错误如下

Google.Apis.Auth.OAuth2.Responses.TokenResponseException: Error:"invalid_grant", Description:"Invalid grant: account not found", Uri:""
   at Google.Apis.Auth.OAuth2.Requests.TokenRequestExtenstions.ExecuteAsync(TokenRequest request, HttpClient httpClient, String tokenServerUrl, CancellationToken taskCancellationToken, IClock clock)
   at Google.Apis.Auth.OAuth2.ServiceAccountCredential.RequestAccessTokenAsync(CancellationToken taskCancellationToken)
   at Google.Apis.Auth.OAuth2.TokenRefreshManager.RefreshTokenAsync()
   at Google.Apis.Auth.OAuth2.TokenRefreshManager.ResultWithUnwrappedExceptions[T](Task`1 task)
   at Google.Apis.Auth.OAuth2.TokenRefreshManager.<>c.<GetAccessTokenForRequestAsync>b__10_0(Task`1 task)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
   at Google.Apis.Auth.OAuth2.TokenRefreshManager.GetAccessTokenForRequestAsync(CancellationToken cancellationToken)
   at Google.Apis.Auth.OAuth2.ServiceAccountCredential.GetAccessTokenForRequestAsync(String authUri, CancellationToken cancellationToken)
   at Google.Apis.Auth.OAuth2.ServiceCredential.InterceptAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Google.Apis.Http.ConfigurableMessageHandler.CredentialInterceptAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Google.Apis.Http.ConfigurableMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndReadAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndDeserializeAsync[TResult](HttpRequestMessage request, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessagingClient.SendAsync(Message message, Boolean dryRun, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message, Boolean dryRun, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message, Boolean dryRun)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message)
   at PCID.Server.Services.HelperMethods.SendNotificationAsync(Notification notification, List`1 userDevices, AppDbContext context)
Google.api.Auth.OAuth2.Responses.TokenResponseException:错误:“无效授权”,说明:“无效授权:找不到帐户”,Uri:“
位于Google.api.Auth.OAuth2.Requests.TokenRequestExtenstions.ExecuteAsync(TokenRequest请求、HttpClient HttpClient、String tokenServerUrl、CancellationToken任务CancellationToken、IClock时钟)
位于Google.api.Auth.OAuth2.ServiceAccountCredential.RequestAccessTokenAsync(CancellationToken任务CancellationToken)
在Google.api.Auth.OAuth2.TokenRefreshManager.RefreshTokenAsync()上
位于Google.api.Auth.OAuth2.TokenRefreshManager.ResultWithUnwrapedExceptions[T](任务'1任务)
在Google.api.Auth.OAuth2.TokenRefreshManager.c.b_uuu10_0(Task`1 Task)
位于System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.c.b_u274_0(对象obj)
位于System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(线程threadPoolThread,ExecutionContext ExecutionContext,ContextCallback回调,对象状态)
---来自引发异常的上一个位置的堆栈结束跟踪---
位于System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(线程threadPoolThread,ExecutionContext ExecutionContext,ContextCallback回调,对象状态)
位于System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task¤tTaskSlot,threadPoolThread)
---来自引发异常的上一个位置的堆栈结束跟踪---
位于Google.api.Auth.OAuth2.TokenRefreshManager.GetAccessTokenForRequestAsync(CancellationToken CancellationToken)
位于Google.api.Auth.OAuth2.ServiceAccountCredential.GetAccessTokenForRequestAsync(字符串authUri,CancellationToken CancellationToken)
在Google.api.Auth.OAuth2.ServiceCredential.InterceptAsync(HttpRequestMessage请求,CancellationToken CancellationToken)
在Google.api.Http.ConfigurableMessageHandler.CredentialInterceptAsync(HttpRequestMessage请求,CancellationToken CancellationToken)
位于Google.api.Http.ConfigurableMessageHandler.SendAsync(HttpRequestMessage请求,CancellationToken CancellationToken)
位于System.Net.Http.HttpClient.FinishSendAsyncBuffered(任务'1 sendTask,HttpRequestMessage请求,取消令牌源cts,布尔处理)
在FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAsync(HttpRequestMessage请求,CancellationToken CancellationToken)
在FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndReadSync(HttpRequestMessage请求,CancellationToken CancellationToken)
在FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndDeserializeAsync[TResult](HttpRequestMessage请求,CancellationToken CancellationToken)
在FirebaseAdmin.Messaging.FirebaseMessagingClient.SendAsync(消息消息,布尔干运行,CancellationToken CancellationToken)
在FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(消息消息、布尔干运行、取消令牌取消令牌)
在FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(消息消息,布尔干运行)
在FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(消息消息)
位于PCID.Server.Services.HelperMethods.SendNotificationAsync(通知通知,列表`1用户设备,AppDbContext上下文)
我已经创建了服务帐户,向服务器添加了密钥,并在GoogleFirebaseCredentials.json中读取