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
Related
I am using the Ingest API to create a timestamp pipeline for an Elasticsearch document.
The format in which Elasticsearch gives the {_ingest.timestamp} is 2022-04-24T01:42:49.036897988Z
Using Set Processor, I am adding the time of ingesting the documents, in the #timestamp field for all the documents, using
PUT _ingest/pipeline/ts-pipeline
{
"description": "Add timestamp field to all documents",
"processors": [
{
"set": {
"field": "timestamp",
"value": "{{_ingest.timestamp}}"
}
},
{
"script": {
"id":"calculate-timestamp"
}
},
{
"remove": {
"field": "timestamp"
}
}
]
}
The definition of the script used above is given below. I need to convert the timestamp, to milliseconds, so for that, I followed this discuss link
POST _scripts/calculate-time
{
"script": {
"lang": "painless",
"source": """DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z'"); LocalDateTime ldt = LocalDateTime.parse(ctx['timestamp'], dtf); ZonedDateTime zdt = ldt.atZone(ZoneId.of('Z')); ctx['#timestamp']=zdt.toInstant().toEpochMilli();"""
}
}
Mapping of #timstamp field is
"#timestamp": {
"type": "date"
}
But when indexing the documents, using this #timestamp field I get, the below error
Text '2022-04-23T10:15:07.024775Z' could not be parsed at index 20
The issue is occurring since the format of ingestion time has changed from yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z' to yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'
Can anyone please let me know, how come the format of the ingestion timestamp has changed to this format yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'
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.
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.
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"
}
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.