【问题标题】:User Rate Limit Exceeded Exception in Admin SDKAdmin SDK 中的 User Rate Limit Exceeded 异常
【发布时间】:2013-12-15 16:10:09
【问题描述】:

我正在使用 Admin SDK。当我更新单个用户时,它工作正常,但是当我尝试更新一堆 (1000) 用户时,我得到了超出用户速率限制异常。请检查下面我的代码并告诉我我错过了什么?或告诉任何建议?

 private Directory getDirectoryService(String adminEmailAddress){
 Directory directoryService = null;
 try {
      Collection<String> SCOPES = new ArrayList<String>();
      SCOPES.add("https://www.googleapis.com/auth/admin.directory.user");
      SCOPES.add("https://www.googleapis.com/auth/admin.directory.user.readonly");
      SCOPES.add("https://www.googleapis.com/auth/admin.directory.group");
      SCOPES.add("https://www.googleapis.com/auth/admin.directory.group.readonly");
      SCOPES.add("https://www.googleapis.com/auth/admin.directory.orgunit");
      SCOPES.add("https://www.googleapis.com/auth/admin.directory.orgunit.readonly");
      SCOPES.add("https://www.googleapis.com/auth/userinfo.profile");

      HttpTransport httpTransport = new NetHttpTransport();
      JacksonFactory jsonFactory = new JacksonFactory();
      GoogleCredential credential = new GoogleCredential.Builder()
      .setTransport(httpTransport)
      .setJsonFactory(jsonFactory)
      .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
      .setServiceAccountScopes(SCOPES)
      .setServiceAccountUser(adminEmailAddress)
      .setServiceAccountPrivateKeyFromP12File(new                                                         java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH)).build();

    directoryService = new Directory.Builder(httpTransport,jsonFactory, credential).setApplicationName("gdirectoryspring").build();

 } catch(Exception e){
   ErrorHandler.errorHandler(this.getClass().getName(), e);
 }
 return directoryService;
}

以下是更新用户代码

Directory directoryService = getDirectoryService("adminEmailAddress");
User user = directoryService.users().get("userPrimaryEmail").execute();
       List<UserOrganization> organizaionList = user.getOrganizations();
       for (int j = 0; j < organizaionList.size(); j++)
       {
         UserOrganization singleOrg = organizaionList.get(j);
         if (singleOrg != null)
         {
          if ("work".equalsIgnoreCase(singleOrg.getCustomType()) ||singleOrg.getPrimary() != null)  
  {
  if (singleOrg.getTitle() != null)
  { 
    singleOrg.setTitle(jobTitle);
   }
  }
 }
  user.setOrganizations(organizaionList);
}

       Update update= directoryService.users().update(primaryEmail, user);
       User userUpdated = update.execute();

在管理控制台中我增加了我的限制,如下所示

Admin SDK   10.0 requests/second/user

但直到我得到超出用户速率限制例外。谁能帮帮我?

【问题讨论】:

    标签: google-app-engine google-admin-sdk


    【解决方案1】:

    您缺少指数退避。 见这里的例子(它的驱动器,但可以调整) https://developers.google.com/drive/handle-errors#implementing_exponential_backoff 在那里你会看到它如何处理像'userRateLimitExceeded'这样的错误

    【讨论】:

    • 不知道为什么这被标记了。它的正确答案。 Hes 获得了预期的 User Rate Limit Exceeded Excepiton,因为当他的限制为每秒 10 个请求时,他在循环中调用 api 1000 次。他只需要处理错误并实施指数退避来重试循环中的当前元素。他也可以在关键区域放置“睡眠”,但这不是通用的,并且会等待超过需要的时间。
    • 我实施了指数备份,现在我遇到了错误。403。 这是一个错误。

      很抱歉,但是您无权访问此页面。 这就是我们所知道的一切。

    • 你能告诉我任何建议吗stackoverflow.com/questions/22009892/…
    • 我添加了 exp backoff ,但遇到了同样的问题。 Thread.sleep((1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-03
    • 2015-11-22
    相关资源
    最近更新 更多