C#GoogleApi错误 - System.Net.HttpListenerException:没有足够的配额可用于处理此命令

时间:2018-02-21 09:06:57

标签: c# .net google-oauth google-sheets-api google-api-dotnet-client

我正在使用API​​ Client Library for .NET(Google.Apis.Sheets.v4)开发应用程序,并且在使用身份验证过程时遇到了麻烦。 SheetsService初始化代码:

private SheetsService __sheetsService;
public GoogleSheetsHelper()
    {
        // initialize sheets API
        UserCredential credential;
        using (var stream =
            new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
        {
            string credPath = System.Environment.GetFolderPath(
                System.Environment.SpecialFolder.Personal);
            credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json");

            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                Scopes,
                "user",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;
        }

        // Create Google Sheets API service.
        __sheetsService = new SheetsService(new BaseClientService.Initializer()
        { 
            HttpClientInitializer = credential,
            ApplicationName = ApplicationName
        }); 
    }

我已经在两台PC,Windows 10和Windows 7上测试了这段代码.Windows 10没有问题,但在Windows 7机器上我收到了这样的例外:

例外文字

  

System.AggregateException:发生了一个或多个错误。 --->   System.Net.HttpListenerException:没有足够的配额可用   处理此命令          在System.Net.HttpListener.SetupV2Config()          在System.Net.HttpListener.Start()          在Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.StartListener()          在Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.d__14.MoveNext()       ---从抛出异常的先前位置开始的堆栈跟踪结束---          在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)          在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)          在Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__8.MoveNext()       ---从抛出异常的先前位置开始的堆栈跟踪结束---          在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)          在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)          在Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__4.MoveNext()       ---从抛出异常的先前位置开始的堆栈跟踪结束---          在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)          在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)          在Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext()          ---内部异常堆栈跟踪结束---          在System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)          在System.Threading.Tasks.Task 1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task 1.get_Result()          在CheesecakeCalculator.GoogleDriveHelper..ctor()          at CheesecakeCalculator.Form1.Form1_Load(Object sender,EventArgs e)          在System.Windows.Forms.Form.OnLoad(EventArgs e)          在System.Windows.Forms.Form.OnCreateControl()          在System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)          在System.Windows.Forms.Control.CreateControl()          在System.Windows.Forms.Control.WmShowWindow(消息& m)          在System.Windows.Forms.Control.WndProc(消息& m)          在System.Windows.Forms.ScrollableControl.WndProc(消息& m)          在System.Windows.Forms.Form.WmShowWindow(消息& m)          在System.Windows.Forms.Form.WndProc(消息& m)          在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)          在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)          在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)       ---> (内部异常#0)System.Net.HttpListenerException(0x80004005):没有足够的配额可用于处理此命令          在System.Net.HttpListener.SetupV2Config()          在System.Net.HttpListener.Start()          在Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.StartListener()          在Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.d__14.MoveNext()       ---从抛出异常的先前位置开始的堆栈跟踪结束---          在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)          在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)          在Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__8.MoveNext()       ---从抛出异常的先前位置开始的堆栈跟踪结束---          在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)          在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)          在Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__4.MoveNext()       ---从抛出异常的先前位置开始的堆栈跟踪结束---          在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)          在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)          at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext()< ---

有谁知道出了什么问题? Myabe需要一些Windows配置来解决这个问题,或者其他一些登录/编写GoogleSheets的方法? 感谢。

1 个答案:

答案 0 :(得分:0)

这不是谷歌错误。

Not enough quota is available to process this command.

  

关闭一些应用程序,然后重试。如果仍然收到此消息,请从“控制面板”中选择“系统”,然后选择“虚拟内存”并增加页面文件的大小。