GMail API快速启动c#失败HttpListener异常

GMail API快速启动c#失败HttpListener异常,c#,api,gmail,C#,Api,Gmail,我正在尝试开始使用Gmail API,以便通过API创建新用户。我在Google开发者的网站上找到了.Net快速启动程序,并按照所有说明进行了操作。程序在GoogleWebAuthorizationBroker.AuthorizationAsync调用线路上失败,出现以下错误: System.AggregateException:HttpListenerException:无法访问网络位置 我使用的是Visual Studio 2017版本15.9.14。有人会认为,罐装的演示代码可以像编写的那

我正在尝试开始使用Gmail API,以便通过API创建新用户。我在Google开发者的网站上找到了.Net快速启动程序,并按照所有说明进行了操作。程序在GoogleWebAuthorizationBroker.AuthorizationAsync调用线路上失败,出现以下错误:

System.AggregateException:HttpListenerException:无法访问网络位置

我使用的是Visual Studio 2017版本15.9.14。有人会认为,罐装的演示代码可以像编写的那样工作

提前感谢所有能帮助解决此问题的人

以下是代码块:

 UserCredential credential;

        using (var stream =
            new FileStream("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 = "token.json";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }
以下是堆栈跟踪:
在System.Net.HttpListener.AddAllPrefixes()中
在System.Net.HttpListener.Start()中
在Google.api.Auth.OAuth2.LocalServerCodeReceiver.StartListener()上
在Google.api.Auth.OAuth2.LocalServerCodeReceiver.d__16.MoveNext()上
---来自引发异常的上一个位置的堆栈结束跟踪---
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()中
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()中

在Google.api.Auth.OAuth2.AuthorizationCodeInstalledApp.

中,凭证应作为文本包含在问题中,而不是发布其图像。凭证应作为文本包含在问题中,而不是发布其图像。
Here is the stack trace:
 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.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.<AuthorizeAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__1.MoveNext()