Java Google Analytics API - Read timed out

前端 未结 1 1779
我寻月下人不归
我寻月下人不归 2021-01-17 21:07

I\'m running a load of queries from Google Analytics which works fine on my local machine. However on the server it seems to have run 3 queries (of 251) before this error: <

1条回答
  •  隐瞒了意图╮
    2021-01-17 21:47

    https://developers.google.com/api-client-library/java/google-api-java-client/errors

     private static HttpRequestInitializer setHttpTimeout(final HttpRequestInitializer requestInitializer) {
          return new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest httpRequest) throws IOException {
              requestInitializer.initialize(httpRequest);
              httpRequest.setConnectTimeout(3 * 60000);  // 3 minutes connect timeout
              httpRequest.setReadTimeout(3 * 60000);  // 3 minutes read timeout
            }};
    
     }
    
    public static Analytics initializeAnalytics() throws Exception {
        // Initializes an authorized analytics service object.
    
        // Construct a GoogleCredential object with the service account email
        // and p12 file downloaded from the developer console.
        HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        GoogleCredential credential = new GoogleCredential.Builder()
            .setTransport(httpTransport)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
            .setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE_LOCATION))
            .setServiceAccountScopes(AnalyticsScopes.all())
            .build();
    
        // Construct the Analytics service object.
        return new Analytics.Builder(httpTransport, JSON_FACTORY,setHttpTimeout(credential))
            .setApplicationName(APPLICATION_NAME).build();
      }
    

    0 讨论(0)
提交回复
热议问题