Connecting to Google Api with a proxy server
<p>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.</p>

<p>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 <strong>"Connection Timeout" or "Unrecognized SSL message, plaintext connection?"</strong>.</p>

<p>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.</p>

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

<p>The Google documentations are not helping much :( . Any help is much appreciated. </p>

<p>My Code for reference:</p>

<pre><code>  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();
</code></pre>