2017-07-26 87 views
1

我正在創建一個頻道,用於接收我的應用程序上的用戶所做的更改。主要的問題是,在2-3次webhooks之後,我收到一個錯誤,說用戶已超出配額限制。已超出Google Drive API配額

這沒有任何意義,因爲我只收到2封郵件(我在ngrok上看到它)。

我已經在谷歌控制檯上的驅動器API和配額。每次我收到一個webhook時,查詢量增加了500個。所以,當用戶進行兩個更改並收到兩個webhook時,查詢數超過了google允許的1000,我收到該錯誤。

這就是代碼,我使渠道:

@GET 
    @Path("/enable") 
    public void enable(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException { 
     Credential credential = initFlow().loadCredential("user"); 
     Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build(); 
     Channel channel = new Channel(); 
     channel.setId(UUID.randomUUID().toString()); 
     channel.setType("web_hook"); 
     channel.setAddress("https://389825dc.ngrok.io/GDriveRest/app/gdrive/webhook"); 
     StartPageToken page = service.changes().getStartPageToken().execute(); 
     GDrive.savedPageToken = page.getStartPageToken(); 
     service.changes().watch(savedPageToken, channel).execute(); 
    } 

而下面一個是網絡掛接:

​​

這是錯誤:

Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden 
{ 
    "code" : 403, 
    "errors" : [ { 
    "domain" : "usageLimits", 
    "message" : "User Rate Limit Exceeded", 
    "reason" : "userRateLimitExceeded" 
    } ], 
    "message" : "User Rate Limit Exceeded" 
} 

這是爲什麼發生了什麼?

回答

0

代碼中有錯誤。我不得不改變如下:

PageToken = changes.getNewStartPageToken(); 

pageToken = changes.getNextPageToken(); 

查詢量巨大是因爲我在每個循環請求新的開始頁面令牌,迫使一個無限循環。

0

您遇到的錯誤在this guide中討論過。

Suggested actions:

  • Raise the per-user quota in the Developer Console project.
  • If one user is making a lot of requests on behalf of many users of a G Suite domain, consider a Service Account with authority delegation (setting the quotaUser parameter).
  • Use exponential backoff.

您也可以嘗試訪問該SO post相關問題。