Difference between dimensions and matrices in google analytics - java

I am new to google analytics and have started to learn how to form a query on a profile, I was not getting the difference between dimensions and matrices in the Query.
Also, how do we concatenate 2 different queries in google analytics ?
I had successfully run the HelloAnalytics.java code with my google analytics account, then I modified the code to fetch real time data. I now wanted to apply more constraints on the data, but was not able to use AND to concatenate 2 stories. My code snippet is -
Analytics.Data.Realtime.Get realtimeRequest = analytics.data().realtime()
.get("ga:" + profileId,
""rt:eventLabel == CLICK_APP AND rt:activeUsers"")
.setDimensions("rt:medium");
It is giving output as
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code": 400,
"errors": [
{
"domain": "global",
"message": "Invalid dimension or metric: rt:eventLabel == CLICK_APP AND rt:activeUsers",
"reason": "badRequest"
}
],
"message": "Invalid dimension or metric: rt:eventLabel == CLICK_APP AND rt:activeUsers"
}

Related

google calendar api delete future events

I am trying to delete future google calendar events, from the docs it tells you to use events.update() and the closest that I have got was with this:
Events events = calendar.events().instances("primary", eventId).execute();
Event instance = events.getItems().get(0);
String[] recurrence = new String[]{"RRULE:UNTIL=" + new DateTime(new Date())};
instance.setRecurrence(Arrays.asList(recurrence));
calendar.events().update("primary", eventId, instance).execute();
and gives me the following:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code": 400,
"errors": [
{
"domain": "global",
"message": "Value 'k6nni7i7p54hb82p3p6eh9emg8_20180830T174500Z' in content does not agree with value 'k6nni7i7p54hb82p3p6eh9emg8'. This can happen when a value set through a parameter is inconsistent with a value set in the request.",
"reason": "invalidParameter"
}
],
"message": "Value 'k6nni7i7p54hb82p3p6eh9emg8_20180830T174500Z' in content does not agree with value 'k6nni7i7p54hb82p3p6eh9emg8'. This can happen when a value set through a parameter is inconsistent with a value set in the request."
}
Any help would be appreciated, thanks!
Deleting events using Calendar API would make use of the events.delete. You can test this using the Try-it.

Create sheet and update data with one request

I want to implement Google sheets api request with one api call.
I managed to implement this code:
List<Request> requests = new ArrayList<>();
List<CellData> values = new ArrayList<>();
values.add(new CellData()
.setUserEnteredValue(new ExtendedValue()
.setStringValue("Hello World!")));
requests.add(new Request().setAddSheet(new AddSheetRequest()
.setProperties(new SheetProperties()
.setTitle("scstc")))
.setUpdateCells(new UpdateCellsRequest()
.setStart(new GridCoordinate()
.setSheetId(0)
.setRowIndex(0)
.setColumnIndex(0))
.setRows(Arrays.asList(
new RowData().setValues(values)))
.setFields("userEnteredValue,userEnteredFormat.backgroundColor"))
);
BatchUpdateSpreadsheetRequest body = new BatchUpdateSpreadsheetRequest().setRequests(requests);
BatchUpdateSpreadsheetResponse response = service.spreadsheets().batchUpdate(spreadsheetId, body).execute();
But I get error:
400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid value at 'requests[0]' (oneof), oneof field 'kind' is already set. Cannot set 'updateCells'",
"reason" : "badRequest"
} ],
"message" : "Invalid value at 'requests[0]' (oneof), oneof field 'kind' is already set. Cannot set 'updateCells'",
"status" : "INVALID_ARGUMENT"
}
at com.google.sheet.impl.GoogleSheetBasicTest1_____1.hello(GoogleSheetBasicTest1_____1.java:133)
Do you how how I can fix this issue?
Each Request object is intended to have just a single value set within it. You are setting two values:
requests.add(new Request()
.setAddSheet(...)
.setUpdateCells(...));
Instead of doing the above, you need to use two request objects:
requests.add(new Request().setAddSheet(...));
requests.add(new Request().setUpdateCells(...));
#Sam is correct, however if you are using the JSON representation make sure that your formatting is set correctly in the dictionaries you are making. I found the following formating helpfull, found in the Google Devs' Formatting cells with the Google Sheets API
blogpost:
reqs = {'requests': [
# frozen row 1, request #1
{'updateSheetProperties': {
'properties': {'gridProperties': {'frozenRowCount': 1}},
'fields': 'gridProperties.frozenRowCount',
}},
# embolden row 1, request #2
{'repeatCell': {
'range': {'endRowIndex': 1},
'cell': {'userEnteredFormat': {'textFormat': {'bold': True}}},
'fields': 'userEnteredFormat.textFormat.bold',
}},
]}
*I am new to adding information to this site. Sorry if this is not he best way to add the information but I just want to help out. I had this problem while using python instead of java and found that it was a simple error of were the brackets where.

Google Analytics Api: Filter by date

Is possible to filter the response by date?
For example, my report query pulls data for 7daysago. But I want to filter this data for each day. This way I don't have to run GoogleAnalytics query every day. Tried using the ga:date dimension as filter but it did not work.
DimensionFilter filter = new DimensionFilter()
.setDimensionName("ga:date").setOperator("LESS_THAN")
.setExpressions(Arrays.asList("today"));
Stacktrace:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code": 400,
"errors": [
{
"domain": "global",
"message": "Invalid value at 'report_requests[0].dimension_filter_clauses[0].filters[0].operator' (TYPE_ENUM), \"LESS_THAN\"",
"reason": "badRequest"
}
],
You can try the core reporting api v4. It offers the dateRange parameter. Let me know if you need some code. For example:
ReportRequest request = new ReportRequest()
.setViewId(VIEW_ID)
.setDateRanges(Arrays.asList(dateRangessArray))
.setDimensions(Arrays.asList(dimensionsArray))
.setMetrics(Arrays.asList(metricsArray))
.setOrderBys(Arrays.asList(orderBy))
.setPageToken(pageToken)
.setPageSize(10000);
where the dateRangesArray could be:
DateRange dateRange = new DateRange();
dateRange.setStartDate(startDate);
dateRange.setEndDate(endDate);
dateRangessArray[0]=dateRange;
The startDate and endDate are strings in the date format: yyyy-mm-dd

google drive java api error 400 when changing file owner

Im trying to change file owner, from writer to owner but I'm still getting:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Bad Request",
"reason" : "badRequest"
} ],
"message" : "Bad Request"
}
And here's some part of source code:
//getting writer permission
Permission permission = service.permissions().get(fileId, permToChange.get(j)).execute();
permission.setRole("owner");
service.permissions().update(fileId, permToChange.get(j), permission).setTransferOwnership(true).execute();
Both accounts current owner and new owner has same domain.
I was trying delete writer account, add new one and change ownership too but always got same result.

modifiedDate and lastViewedByMeDate query not woring in Drive API Java

I have a query that modifiedDate = '2013-09-01T12:00:00' and lastViewedByMeDate = '2013-09-01T12:00:00' those type of queries are not working and throws error as:
com.google.api.client.googleapis.json.GoogleJsonResponseException:
500 Internal Server Error
{
"code" : 500,
"errors" : [ {
"domain" : "global",
"message" : "Internal Error",
"reason" : "internalError"
} ],
"message" : "Internal Error"
}
My Code is
String searchQuery="lastViewedByMeDate = '2013-09-01T12:00:00'";
// String searchQuery="modifiedDate = '2013-09-01T12:00:00'";
Files.List request = this.driveService.files().list();
request.setQ(searchQuery);
FileList files = request.execute();
for (File file : files.getItems()) {
// ...........
}
There is no error in code since this type of queries are not running.
Looks like a bug.
Using https://developers.google.com/drive/v2/reference/files/list#try-it, your query throws a 500, but changing the comparison operator from '=' to '>=' works OK.
It is a bit unusual to query for a precise date and time anyway (remember that timestamps are often updated asynchronously in Google Drive). So it maybe that you can use a date range to meet your needs.
It may well be that the bug is simply in the documentation, and that '=' is not actually supported.

Categories