简体   繁体   中英

com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request

I have getting an error like

com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request { "code" : 400, "errors" : [ { "domain" : "global", "message" : "Selected dimensions and metrics cannot be queried together.", "reason" : "badRequest" } ], "message" : "Selected dimensions and metrics cannot be queried together."

Metrics are below: "ga:uniquePurchases,ga:itemRevenue,ga:transactionTax,ga:transactionShipping

Dimensions below: "ga:productName";

 if (accessToken != null && refreshToken != null) {
            JacksonFactory jacksonFactory = new JacksonFactory();

             GoogleCredential credential =new GoogleCredential.Builder().setTransport(netHttpTransport)
                                                   .setJsonFactory(jacksonFactory).setClientSecrets(CLIENT_ID, CLIENT_SECRET).build();
                               credential.setAccessToken(accessToken);
                               credential.setRefreshToken(refreshToken);
                               analytics=new Analytics.Builder(netHttpTransport, jacksonFactory, credential).setApplicationName(APPLICATION_NAME).build();
            try {
                //AT a time we can get only 7 dimensions and 10 metrics
                apiQuery = analytics.data().ga().get("ga:" + gleTokenInf.getProfileId(), TimeStamp1, TimeStamp2,getMetrics());
                apiQuery.setDimensions(getDimensions());
                gaData = apiQuery.execute();
                log.info("Succesfully got the data for GA MOM Report from Analytics Interface ");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

You cannot query all combinations of dimensions and metrics in GA API. Your query will work if ga:productName is replaced with ga:transactionId.

Test API queries here here - https://ga-dev-tools.appspot.com/query-explorer/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM