java - Accessing Google Analytics API with a service account returns invalid_grant error -


we have google analytics account keeps track of frequent searched words. want fetch report in java. trying follow below link: hello analytics api: java quickstart service accounts

  1. created project , enabled analytics api
  2. created client id. created service account. when prompted key type select p12 while creating service account, , saved generated key client_secrets.p12
  3. added service account email id (208051463715-compute208051463715-compute@developer.gserviceaccount.com)to@developer.gserviceaccount.com) google analytics account. read & analyze permissions assigned
  4. installed google client library , set sample code replaced values of service_account_email , key_file_location present in sample code appropriate values developer console.

service_account_email:208051463715-compute208051463715-compute@developer.gserviceaccount.com)to@developer.gserviceaccount.com

key_file_location :we kept file in same directory kept analytics.java file.below link: , following steps mentioned below.

but getting following error:

when running java class getting exception follows:

com.google.api.client.googleapis.auth.oauth2.googlecredential@39fb3ab6 com.google.api.client.auth.oauth2.tokenresponseexception: 400 bad request { "error": "invalid_grant" } @ com.google.api.client.auth.oauth2.tokenresponseexception.from(tokenresponseexception.java:105) @ com.google.api.client.auth.oauth2.tokenrequest.executeunparsed(tokenrequest.java:287) @ com.google.api.client.auth.oauth2.tokenrequest.execute(tokenrequest.java:307) @ com.google.api.client.googleapis.auth.oauth2.googlecredential.executerefreshtoken(googlecredential.java:384) @ com.google.api.client.auth.oauth2.credential.refreshtoken(credential.java:489) @ com.google.api.client.auth.oauth2.credential.intercept(credential.java:217) @ com.google.api.client.http.httprequest.execute(httprequest.java:859) @ com.google.api.client.googleapis.services.abstractgoogleclientrequest.executeunparsed(abstractgoogleclientrequest.java:419) @ com.google.api.client.googleapis.services.abstractgoogleclientrequest.executeunparsed(abstractgoogleclientrequest.java:352) @ com.google.api.client.googleapis.services.abstractgoogleclientrequest.execute(abstractgoogleclientrequest.java:469) @ com.hm.backstage.components.util.helloanalytics.getfirstprofileid(helloanalytics.java:68) @ com.hm.backstage.components.util.helloanalytics.main(helloanalytics.java:33**)


Comments