Advertisement
Guest User

Untitled

a guest
May 5th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public HttpRequestInitializer getCredentials() throws GeneralSecurityException, IOException {
  2.  
  3. HttpRequestInitializer httpRequestInitializer;
  4.  
  5. if (com.google.appengine.api.utils.SystemProperty.environment.value() == com.google.appengine.api.utils.SystemProperty.Environment.Value.Development) {
  6.  
  7. String certificate = "/token.p12";
  8. File privateKey = null;
  9.  
  10. try {
  11. privateKey = new File(getClass().getResource(certificate).toURI());
  12. } catch (URISyntaxException e) {
  13. log.log(Level.SEVERE, e.getMessage(), e);
  14. }
  15.  
  16. httpRequestInitializer = new GoogleCredential.Builder()
  17. .setTransport(new NetHttpTransport())
  18. .setJsonFactory(new JacksonFactory())
  19. .setServiceAccountId("XXXX@developer.gserviceaccount.com")
  20. .setServiceAccountPrivateKeyFromP12File(privateKey)
  21. .setServiceAccountScopes(Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY))
  22. .build();
  23.  
  24. } else {
  25.  
  26. httpRequestInitializer = new AppIdentityCredential(Arrays.asList(AnalyticsScopes.ANALYTICS_READONLY));
  27.  
  28. }
  29.  
  30. return httpRequestInitializer;
  31. }
  32.  
  33. com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 OK
  34. {
  35. "code" : 403,
  36. "errors" : [ {
  37. "domain" : "global",
  38. "message" : "User does not have any Google Analytics account.",
  39. "reason" : "insufficientPermissions"
  40. } ],
  41. "message" : "User does not have any Google Analytics account."
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement