Google日历RateLimitExceeded错误

时间:2017-05-23 14:01:43

标签: c# api calendar limit rate

我一直遇到Google Calendar API的问题。

我每天可以进行100万次查询,每个用户每100秒查询25000次查询 我有一个任务(用C#编写),它为每个决定授权应用程序与Google日历和我的软件同步的用户提供查询。
我没有超过速率限制,但对于特定用户,我收到此消息:

错误讯息:

  

Google.Apis.Requests.RequestError超出速率限制[403]错误[消息[超出速率限制]位置[ - ]原因[rateLimitExceeded]域[usageLimits]]

堆栈追踪:

Google.Apis.Requests.ClientServiceRequest`1.Execute()

有人可以向我解释为什么会发生这种情况,我该如何解决?

编辑: 这是我的C#代码

 //for each user
  foreach (var utente in clientContext.TbUtentiDatiDescrittivi)
  {
            var fileDataStore = GetFileDataStore();

            //get token from path
            var token = fileDataStore.GetAsync<TokenResponse>(utente.userID).Result;

            var credential = new UserCredential(GetCodeFlow(fileDataStore), userID, token);

            //check if token is expired, in case I update it
            if (credential.Token.IsExpired(credential.Flow.Clock))
            {
                if (!credential.RefreshTokenAsync(CancellationToken.None).Result)
                {
                    //error, delete file
                    credential.Flow.DeleteTokenAsync(userID, CancellationToken.None).Wait();
                }
            }

            // Create Google Calendar API service.
            var service = new CalendarService(new BaseClientService.Initializer()  
            {
                   HttpClientInitializer = credential,
                   ApplicationName = APPLICATION_NAME,
            });

          //get request
          EventsResource.ListRequest request = service.Events.List("primary");
           //...

             //get list of events
             var lstAttivitaCalendar = request.Execute().Items.ToList();//here I get the error


           //then I make some queries like
           service.Events.Delete("primary", attivita.CalendarGoogleID).Execute();
           //or
            service.Events.Update(attivitaCalendar, "primary", attivitaCalendar.Id).Execute();
}

0 个答案:

没有答案