Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public HttpRequestInitializer getCredentials() throws GeneralSecurityException, IOException {
- HttpRequestInitializer httpRequestInitializer;
- if (com.google.appengine.api.utils.SystemProperty.environment.value() == com.google.appengine.api.utils.SystemProperty.Environment.Value.Development) {
- String certificate = "/token.p12";
- File privateKey = null;
- try {
- privateKey = new File(getClass().getResource(certificate).toURI());
- } catch (URISyntaxException e) {
- log.log(Level.SEVERE, e.getMessage(), e);
- }
- httpRequestInitializer = new GoogleCredential.Builder()
- .setTransport(new NetHttpTransport())
- .setJsonFactory(new JacksonFactory())
- .setServiceAccountId("XXXX@developer.gserviceaccount.com")
- .setServiceAccountPrivateKeyFromP12File(privateKey)
- .setServiceAccountScopes(Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY))
- .build();
- } else {
- httpRequestInitializer = new AppIdentityCredential(Arrays.asList(AnalyticsScopes.ANALYTICS_READONLY));
- }
- return httpRequestInitializer;
- }
- com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 OK
- {
- "code" : 403,
- "errors" : [ {
- "domain" : "global",
- "message" : "User does not have any Google Analytics account.",
- "reason" : "insufficientPermissions"
- } ],
- "message" : "User does not have any Google Analytics account."
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement