-1

我在將分析數據作爲來源轉儲時發現此錯誤。com.google.api.client.googleapis.json.GoogleJsonResponseException:403禁止例外

任何人都可以說這可能是什麼.. ??

public Get getAnalyticsReportDefination() { 
    String month = ((fromCal.get(Calendar.MONTH) + 1) < 10 ? "0" + (fromCal.get(Calendar.MONTH) + 1) : "" + (fromCal.get(Calendar.MONTH) + 1)); 
    String date = (fromCal.get(Calendar.DATE) < 10 ? "0" + fromCal.get(Calendar.DATE) : "" + fromCal.get(Calendar.DATE)); 
    String toMonth = ((toCal.get(Calendar.MONTH) + 1) < 10 ? "0" + (toCal.get(Calendar.MONTH) + 1) : "" + (toCal.get(Calendar.MONTH) + 1)); 
    String toDate = (toCal.get(Calendar.DATE) < 10 ? "0" + toCal.get(Calendar.DATE) : "" + toCal.get(Calendar.DATE)); 
    String TimeStamp1 = fromCal.get(Calendar.YEAR) + "-" + month + "-" + date; 
    String TimeStamp2 = toCal.get(Calendar.YEAR) + "-" + toMonth + "-" + toDate; 
    log.info("Google Analytics Stats for date range " +TimeStamp1 + " to " +TimeStamp2); 
    String accessToken = gleTokenInf.getAccessToken(); 
    String refreshToken = gleTokenInf.getRefreshToken(); 
    Analytics analytics = null; 
    NetHttpTransport netHttpTransport = new NetHttpTransport(); 

    if (accessToken != null && refreshToken != null) { 
     JacksonFactory jacksonFactory = new JacksonFactory(); 
     GoogleCredential credential =new GoogleCredential.Builder().setTransport(netHttpTransport) 
               .setJsonFactory(jacksonFactory).setClientSecrets(CLIENT_ID, CLIENT_SECRET).build(); 
          credential.setAccessToken(accessToken); 
          credential.setRefreshToken(refreshToken); 
     analytics=new Analytics.Builder(netHttpTransport, jacksonFactory, credential).setApplicationName(APPLICATION_NAME).build(); 
     try { 
      //AT a time we can get only 7 dimensions and 10 metrics 
      apiQuery = analytics.data().ga().get("ga:" + gleTokenInf.getProfileId(), TimeStamp1, TimeStamp2,getMetrics()); 
      apiQuery.setDimensions(getDimensions()); 
      StringBuilder source = new StringBuilder(); 
      int len = FilterConditions.length; 
      for (int i = 0; i < len; i++) { 
        source.append(FilterConditions[i]).append(filterExpression).append(FilterValues[i]).append(FilterType); 
       } 
      apiQuery.setFilters(source.substring(0, source.length() - 1)); 
      gaData = apiQuery.execute(); 
     } catch (Exception ex) { 
      ex.printStackTrace(); 
     } 
    } 
    return apiQuery; 
} 

的錯誤是:提前

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden 
{ 
    "code" : 403, 
    "errors" : [ { 
    "domain" : "usageLimits", 
    "message" : "Daily Limit Exceeded. The quota will be reset at midnight Pacific Time (PT). You may monitor your quota usage and adjust limits in the API Console: https://console.developers.google.com/apis/api/analytics/quotas?project=433676821622", 
    "reason" : "dailyLimitExceeded", 
    "extendedHelp" : "https://console.developers.google.com/apis/api/analytics/quotas?project=433676821622" 
    } ], 
    "message" : "Daily Limit Exceeded. The quota will be reset at midnight Pacific Time (PT). You may monitor your quota usage and adjust limits in the API Console 
} 

---------- 

metrics: ga:transactions,ga:transactionRevenue,ga:itemRevenue,ga:transactionShipping,ga:transactionTax 

dimensions: ga:campaign,ga:adGroup 

感謝。

+0

_「每日限制超出」_的哪一部分不清楚? –

+0

編輯不起作用。錯誤是告訴你,你已經超出了你允許執行的每日查詢次數。 –

+0

那麼可能是什麼解決方案。 – Sanju

回答

0

使用Google Analytics(分析)API時,您應該注意幾個配額。

首先是您的應用程序每天最多可以提出50000個請求。第二個是您嘗試訪問的每個視圖每天最多可以創建10000個請求。

超出每日限制。配額將在太平洋時間午夜(PT)重置

表示您已超過這些配額之一。找出問題的最簡單方法是嘗試使用不同的視圖提出請求。如果它起作用,那麼你知道你在第一個視圖中刪除了配額。如果不是這樣,這意味着你吹掉了項目的配額。無論您將哪個配額導出,都將無法再次訪問API,直到西半山配額在西部時間重置爲止。

您可以請求擴展每個項目的50000個請求。通過Google開發者控制檯,在其中啓用分析API並在配額部分下。大約需要一個月左右的時間才能獲得擴展程序,以便在每天使用80%的配額時使用擴展程序。

您無法每天請求10000個請求的擴展。

+0

謝謝DalmTo。 – Sanju