Я пытаюсь создать службу windows, которая выполняет некоторые действия с Gmail. Я разработал код, и он отлично работает в моем местном Macine. Проблема возникает при его развертывании на сервере.
*One or more errors occurred.The network location cannot be reached. For information about network troubleshooting, see Windows Help at System.Net.HttpListener.AddAllPrefixes() at System.Net.HttpListener.Start() at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.StartListener() at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.<ReceiveCodeAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.<AuthorizeAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---*
Кажется, он пытается запустить браузер на сервере и в конечном итоге с вышеуказанными исключениями. Вот мой код:
public static GmailService GetGmailService()
{
UserCredential credential;
using (var stream =
new FileStream(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\credentials.json",
FileMode.Open,
FileAccess.Read))
{
// The file token.json stores the user's access and refresh tokens, and is created
// automatically when the authorization flow completes for the first time.
string credPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"xxxxxx@gmail.com",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
// Create Gmail API service.
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
return service;
}
Заранее спасибо за помощь.