title: How to use Google analytics authorization without web browser interaction using service accounts?
body: <p>I am trying to access google analytics data without the need for a user to interact with a browser to authorize this access -- in this case, it is our own data that we wish to display outside of Google Analytics.</p>
  
  <p>Google describes service accounts here: <a href="https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtAuthorization" rel="nofollow">https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtAuthorization</a></p>
  
  <p>and I think based on the description that this is what I am looking for. It is necessary to follow the steps to obtain things used in the following code:</p>
  
  <pre><code> GoogleCredential credential = new  
                        GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
                  .setJsonFactory(JSON_FACTORY)
                  .setServiceAccountId("758873802454-   s8o6hgkjjn8rm15so46pvrqu1lgn4squ@developer.gserviceaccount.com")
                  .setServiceAccountScopes(Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY))
                  .setServiceAccountPrivateKeyFromP12File(new File("C:\\Users\\jeff.miller\\Downloads\\67ed856e6b6b55e846f53e78e76b28141c98eeff-privatekey.p12"))
                  .setServiceAccountUser("758873802454-s8o6hgkjjn8rm15so46pvrqu1lgn4squ.apps.googleusercontent.com")
                   //.setService("AIzaSyCM1FlW4fs38NPSOesXULeSnBlpYd783Xk")
                  .build();
  </code></pre>
  
  <p>The p12 file is downloaded and we also get a new service account with client id and email address that I put I think in the correct places in the constructor code above. Moreover there is the need to do configuration from the Google console. I have gotten various error messages, most recently: "Invalid impersonation prn email address" but I have also gotten 
  messages indicating that the account did not have permission no matter what I tried.</p>
  
  <p>The code is based on examples that are obsolete -- for example, in the example setServiceAccountScopes took a string rather than a singleton.</p>
  
  <p>It would be great to find an up-to-date Java example including hints about configuration in the console, that gives me the ability to access Google Analytics without browser interaction.</p>
  
  <p>Thanks.</p>