How to set ReadTimeOut for Analytics

986 views
Skip to first unread message

Heita

unread,
Mar 14, 2012, 11:05:39 AM3/14/12
to google-api-java-client
The class: com.google.api.services.analytics.Analytics

I can not find the method to set read time out. Even I have set the
timeout of HttpTransport, it still throw an error after 20s of
fetching data.

Could someone help me?

Ravi Mistry

unread,
Mar 15, 2012, 2:09:11 PM3/15/12
to google-api-...@googlegroups.com
Hello Heita,


Example:

final Analytics analytics = Analytics.builder(new NetHttpTransport(), jsonFactory)
  ...
  .setHttpRequestInitializer(new HttpRequestInitializer() {
    @Override
    public void initialize(HttpRequest httpRequest) {
      httpRequest.setReadTimeout(30000);  // 30 seconds timeout
    }
  })
  .build();

Thanks,
Ravi

Heita

unread,
Mar 16, 2012, 5:12:29 AM3/16/12
to google-api-...@googlegroups.com
Hello Ravi:

    Now I am using the class com.google.api.client.googleapis.auth.oauth2.GoogleCredential as  HttpRequestInitializer for  Analytics.builder.(I think it's the way recommended)
    Is there any way to initialize the read time out of it?

  Here is my code:

       GoogleCredential googleCredential = null;

        Builder builder = new GoogleCredential.Builder();

        builder.setTransport(transport);
        builder.setJsonFactory(jsonFactory);

        googleCredential = builder.build().setFromTokenResponse(tokenResponse);

        com.google.api.services.analytics.Analytics.Builder analyticsBuilder = Analytics.builder(
             transport ,  jsonFactory );
        analyticsBuilder.setHttpRequestInitializer(googleCredential);


Thanks
Heita

Ravi Mistry

unread,
Mar 17, 2012, 9:00:41 AM3/17/12
to google-api-...@googlegroups.com
Hi Heita,

Yes you can initialize the read time out as well:

GoogleCredential credential = ....

final Analytics analytics = Analytics.builder(new NetHttpTransport(), jsonFactory)
  ...
  .setHttpRequestInitializer(new HttpRequestInitializer() {
    @Override
    public void initialize(HttpRequest httpRequest) {
      credential.initialize(httpRequest);
      httpRequest.setReadTimeout(30000);  // 30 seconds timeout
    }
  })
  .build();

Thanks,
Ravi

Meng Li

unread,
Mar 19, 2012, 4:35:59 AM3/19/12
to google-api-...@googlegroups.com
It works! Thank you very much.

Yuan Fang

unread,
Sep 12, 2013, 9:10:33 PM9/12/13
to google-api-...@googlegroups.com, rmi...@google.com
I dislike this kind of lazy answer.
It does not help.
A few lines more detail will make it much better.

yogila...@willyweather.com

unread,
May 10, 2017, 10:59:36 AM5/10/17
to google-api-java-client, rmi...@google.com
just removed the  credential.initialize(httpRequest); and now its working fine.  
Reply all
Reply to author
Forward
0 new messages