How to get the metrics value in Google Business Profile Performance - java

I was using Google My business V4.9, I used to do
for (LocationMetrics locationMetrics : reportInsights.getLocationMetrics()) {
List <MetricValue> metricValue = locationMetrics.getMetricValues();
metricValue.get(0).getDimensionalValues().get(0).getValue())
and I was getting the value of the specific metric, but now after they have changed it to Business Profile Performance, I get a response of type GetDailyMetricsTimeSeriesResponse, I can't find any documentation that explains what is the structure of this response and how can I get the value of the metrics.
I'm using this answer to create the request
I can see that the new API have this object TimeSeries as a response.

Related

OpenStack Projects List HTTP request ignoring pagination "limit=" parameter

I am trying to retrieve a list of projects from the OpenStack API, and would like to use pagination in order to retrieve n projects at a time.
In the OpenStack documentation, it states that I can append "/?limit=n" to the URL and up to n results will be fetched accordingly.
However, when executing the GET request to the URL as follows:
https://identity-3.eu-de-1.cloud.sap/v3/auth/projects/?limit=1
I still get ALL projects. I can't seem to understand what I am missing.
NOTE: the request itself works and returns results as needed, but simply ignores the limit parameter (this is not an authentication issue).
I think it does not all OpenStack API provide limit parameter
In keystone API doc, there is no limit parameter in Request parameter descriptions for /v3/auth/projects API
keystone-project-API-doc
Other services like cinder volume list, it provides limit parameter in doc
cinder-volume-API-doc

HazelCast Rest-Client Response Content -Type Configuration Problem

I have integrated the hazelcast mechanism in my project. I am able to store the the Data in the map by using the hazelcast instance reference. But I am feeling difficulty to set the response type for the rest client apis.
I am getting the response as type of Content-Type →application/binary but the required format is Content-Type:application/json
I followed the documentation provided in:HazelCast RestClient Documentation
I am storing the data by using the hazelcast instance in the below format:
Sample Format:
*Map<String, User> mymap = hazelcastinstance.getMap("testMap");
User user = new User();
mymap.put("mykey", user);*
Any one please help me with this issue
Thanks in advance
Url:
(Get Request)
http://localhost:5701/hazelcast/rest/maps/testMap/mykey
Hazelcast currently stores data in binary form or in Java object. JSON support is coming out in 3.12, which is already in BETA. You can access 3.12-BETA here: https://hazelcast.org/download/
Unfortunately, REST would not be able to return JSON in 3.12. Perhaps, something can be added in one of the later versions, possibly 4.0.

Google Analytics Report API v4: get Sessions and Revenue data

I trying to get Sessions, Revenue, Transactions, Bounce Rate data from Google Analytics Report API v4
with grouping by Chanel:
Organic search
Email
Direct
Branded Paid Search
Social
Referral
.. etc
Right now I'm programming a Java module with test Request which has setted following parameters:
Dimensions:
ga:acquisitionTrafficChannel;
Metrics:
ga:sessions
ga:percentNewSessions
ga:newUsers
When I use ga:acquisitionTrafficChannel + ga:sessions GA Report api returns values, but when I try to add in request ga:percentNewSessions, ga:newUsers, it returns error:
{
"domain": "global",
"message": "Selected dimensions and metrics cannot be queried together.",
"reason": "badRequest"
}
To perform request in code I do following:
DateRange dateRange = new DateRange();
dateRange.setStartDate("2015-06-15");
dateRange.setEndDate("2015-06-30");
ReportRequest request = new ReportRequest()
.setViewId(context.getProperty(VIEW_ID).evaluateAttributeExpressions().getValue())
.setDateRanges(Arrays.asList(dateRange))
.setDimensions(Arrays.asList(
new Dimension().setName("ga:acquisitionTrafficChannel")
))
.setMetrics(Arrays.asList(
new Metric().setExpression("ga:sessions"),
new Metric().setExpression("ga:percentNewSessions"),
new Metric().setExpression("ga:newUsers")
));
ArrayList<ReportRequest> requests = new ArrayList<>();
requests.add(request);
GetReportsRequest getReport = new GetReportsRequest().setReportRequests(requests);
GetReportsResponse response = service.reports().batchGet(getReport).execute();
How to do request correctly? Is in the right direction do I go?
Because as I said, I will need to do same thing with Revenue, Bounce Rate..
but I not fully understand how to combine Metrics and Dimensions without errors.
Thanks for any help
About my question:
As solution for my needs I used following combination in code:
To get all Channel groups ("Organic Search, Email, Direct, etc") I used following dimension:
ga:channelGrouping - it will return all
To get values for Sessions, Revenue, Transactions, Bounce Rate, etc I used following metrics:
ga:sessions
ga:transactionRevenue
ga:transactions
ga:bounceRate
Also here can be more metrics if it is needed.
Maybe it will be useful to somebody.
Actually, question about error with combination in question (with ga:acquisitionTrafficChannel) is still open :)

Can Elasticsearch stream the SearchResponse?

I have a rest application that can export some report data from Elasticsearch. It is easy to do with the Java API:
SearchResponse response = getClient()
.prepareSearch("my_index_name")
.setQuery(QueryBuilders.someQuery())
.addAggregation(AggregationBuilders.someAggregation())
.get();
The problem starts with the big responses. Using this code snippet, the response is read to build the SearchResponse object in memory. In my case, the response does not fits in memory.
Paging cannot help because we often need to return the full data and Aggregations do not support paging yet.
I know that I can use the Elasticsearch REST API to read the response as stream, but manually build the request it is cumbersome. I really want something like this:
// my dream API
InputStream response = getClient()
.prepareSearch("my_index_name")
.setQuery(QueryBuilders.someQuery())
.addAggregation(AggregationBuilders.someAggregation())
.getStream();
So, can the Elasticsearch Java API stream the SearchResponse?
A proposal for streaming results does exist but it doesn't seem to have picked up steam so far and was closed (for now).
There's a way to do it with XContentBuilder but that still requires the whole response to be in memory before being sent.
It might not be what you want, but that's the closest thing that I know which could fulfill your need. Worth giving it a try.
I believe there is no way to obtain an InputStream from the Java API (but I might be wrong). I also think there is no way to directly obtain an InputStream in Jest (a REST-based Elasticsearch Java API).
You mention that it is cumbersome to create the search request to the _search endpoint yourself: if you're referring to building the actual json query, I just would like to point out that once you have a SearchSourceBuilder, you can call toString() on it to get a fully working json representation of your query.
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(this.getQuery())
.from(this.getFrom())
.size(this.getSize())
.fetchSource(this.getSource(), null);
this.getSort().forEach(sourceBuilder::sort);
sourceBuilder.toString() // the json representation

Best Practice Using JSON to pass data from Java to PHP and PHP to Java Securely

I have been working on an android application project that uses HTTP Get to send and receive data from MySQL through a PHP file using JSON from Java.
I have lately been running into some issues in theory behind best practices using HTTP Transport and passing Parameters via a URL.
First Question:
How should I be passing my data to my PHP Webservices ?
Currently I am just passing the data through single parameters using key value pairs like so:
myurl.com/retrieveinfo.php?user_id=453&password=sha1-hash-value
Should I be moving this type of request to append a JSON object onto the URL instead? like so:
myurl.com/retrieveinfo.php?{\"users\":{\"username\":\"User1Name\" ,\"user_id\":453 , \"password\":\"sha1-hash-value\"}}
Second Question:
*How should I be handling the JSON Response from the Server ? Do I need to push this work off to a handler and make sure the UI Thread is not the one doing this work? *
Currently I am just parsing the JSON using separate methods for each Object Type such as
User.Class
private void parseUserInfo(JSONObject response){
// Do all my Parsing for a User Object
try{
JSONArray users = response.getJSONArray("users");
JSONObject user = users.getJSONObject(0);
// Get the User info etc...
}catch(JSONException ex){
ex.printStackTrace();
}
}
Notes.Class
private void parseNotes(JSONObject response){
// Do all my Parsing for a Note Object
try{
JSONArray notes = response.getJSONArray("notes");
for (int index = 0; index < notes.length() ; index++)
{
JSONObject note = notes.getJSONObject(index);
// Get all the note info etc...
}
}catch(JSONException ex){
ex.printStackTrace();
}
}
Third Question:
I would like my PHP server files to only work for my Application. So what is the best way to secure my PHP files on my server so a request to my files wont go through if its run in a browser ?
Should I be sending some temp key that only my application knows about ?
Thanks
First Question:
You don't really want to put a JSON object on the url as a query parameter. The real two debates that I see is that you either 1) use the key value pairs you were using, or 2) make this a POST and send the JSON as a payload.
Since you are not planning on exposing the API to anyone, I don't really find it important for you to follow standard nomenclatures. Do whatever you want to do. However, from a REST standpoint, anything that retrieves info should be a GET call, and the data should be key-value pairs on the query string. However, it looks like you are passing in a username and password (ok, the sha of the pass). It is considered best practice to always pass user info as the payload. So almost all login type protocols use a POST for user data. User-id's or session id's are common in the query string but usernames and passwords should almost always be in a payload.
Note: sometimes in TLS (SSL) it is considered ok to include these things in the query string.
Second Question:
Honestly, I would just use Jackson. https://github.com/FasterXML/jackson
But otherwise, it is normal to have a seperate layer for parsing. In otherwords, one class handles all the parsing. You do not want to put this code inside your models if you can avoid it. The new layer would handle parsing and would pass the Java Model objects down to the next layer.
Third Question:
The easiest way to do this would simply be to check the user-agent header on the request. Make sure that the user-agent is your application, and not a browser.
However, it would still be possible for people to "spoof" this. Using a temp key wouldn't really help either, because once people sniff the traffic they can figure out the temp key.
The standard thing here is to do some type of session based key, where the application sends some type of MAC in order to prove it is a valid client.
You could also consider using OAUTH2 to protect your api's.

Categories

Resources