0

My company's website is using google analytics to track various details, now we have a requirement to fetch all those raw data from google analytics servers and process using out internal tool.

I've created a small Java code using the HelloAnalytics Sample code (Analytics V4 and oAuth 2.0) to fetch session data from google servers. When i am running the same code from my personal computer it's running fine; but when i try to execute the same from company network, it fails throwing either "Connection Timeout" or "Unrecognized SSL message, plaintext connection?".

These issues are obviously due to firewall or the proxy server which is used by my company. I want to know if there's any way to connect to Google Analytics from a corporate network which uses a proxy server.

I've added the http.proxyHost and http.proxyPort as system property, nothing changed, got the same error. But when i added https.proxyHost and https.proxyPort instead of http port, it starting throwing error message "PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"

The Google documentations are not helping much :( . Any help is much appreciated.

My Code for reference:

  HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
  JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();

  //Trying both Explict token and also Client-Serect.json
  GoogleCredential credential2 = new GoogleCredential().setFromTokenResponse(new TokenResponse().setAccessToken("Some token"));

  GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream("client-secret.json")).createScoped(AnalyticsReportingScopes.all());
  AnalyticsReporting service = new AnalyticsReporting.Builder(httpTransport, JSON_FACTORY, credential).build();      

  GetReportsRequest getReport = //Create the report object to fetch user sessions

  GetReportsResponse response = service.reports().batchGet(getReport).execute();
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Prabal Nandi
  • 141
  • 3
  • 13
  • 1
    http://stackoverflow.com/q/14262519/1841839 It appears the Google Java client library supports it try Googling after that. Note: You cant get raw google analytics data out of the API its processed and it is also limited to what you can request out. – Linda Lawton - DaImTo Oct 24 '16 at 09:39
  • thanks for pointing out in the correct direction. Based on the link i need to get the google certificates and add to the trust store. Where can i find the certificates? i tried to fetch the cert using "openssl s_client -connect google.com:443" but it kind of crashed throwing error. – Prabal Nandi Oct 25 '16 at 10:24
  • No idea really. I was mostly guessing I did it once a few years ago. I know its possible I just cant remember how :) – Linda Lawton - DaImTo Oct 25 '16 at 11:21

0 Answers0