Issues with Google GeoLocation API - java

I am trying to get location co-ordinates based on WiFi access point details using Google GeoLocation API. The issue is I am always returned the same co-ordinate for every request.
The URL to which I am passing my JSON request is: https://www.googleapis.com/geolocation/v1/geolocate?key=MY_API
The JSON data that I am passing is:
{
"radioType":"wcdma",
"homeMobileNetworkCode":"0",
"homeMobileCountryCode":"234",
"carrier":"BT",
"wifiAccessPoints":
{
"signalStrength":-73,
"age":0,
"macAddress":"BSSID HERE",
"channel":6
}
}
I am UK based, which is why I have set MNC to 234. Also, I can only use wifi for location services as there is no GPS installed in the current configuration.
The response that I always receive from Google is:
{
"location":
{
"lat": 51.517098999999995,
"lng": -0.146084
},
"accuracy": 18000.0
}
I receive that response for all my requests, irrespective of any BSSID that I pass as request. Could you tell me what am I doing wrong here? I am passing this data as a POST request using Java (using the standard HTTP Connection listed here)

If you take a look at the Google Geolocation API Documentation:
https://developers.google.com/maps/documentation/business/geolocation/#cell_tower_object
You can see the 'cellTowers' and 'wifiAccessPoints' sections are setup to use JSON Arrays.
So, to fix your example, it should look like this:
{
"radioType":"wcdma",
"homeMobileNetworkCode":"0",
"homeMobileCountryCode":"234",
"carrier":"BT",
"wifiAccessPoints":
[{
"signalStrength":-73,
"age":0,
"macAddress":"BSSID HERE",
"channel":6
}]
}

Related

How to get a URL in response of a POST request that navigates to GET request in Spring Boot?

I'm working on a project in which I'm creating (POST) a book. Once the book is created, a unique bookId is generated and the response looks something like this:
{
"bookId":"123pqr",
"author":"Abc",
"title": "Book1"
}
I have one GET request which basically fetches the book details using bookId - http://localhost:port/{bookId}.
I'm trying to get this above URL whenever I create a book so that my response should look like this:
{
"bookId":"123pqr",
"author":"Abc",
"title": "Book1"
"url": "http://localhost:port/{bookId}"
}
So that if a user clicks on the URL, the user should be navigated to a GET request http://localhost:port/{bookId}. I think I can just hardcode a string "http://localhost:port/" and then append bookId to it and provide the same in response. However, I'm not sure how to set the request type as GET when the URL is clicked. Also, is there a better way to avoid harcoding? Could someone please help? Thanks in advance!
You do not need to specify anything to consider a URL as a GET.
This is natively part of every browser.
However, you could think a bit further and use HATEOAS which specifies the kind of relationship for a specific href
Your response would look like the following where self is standardized to be a GET request since it's the retrieval of the resource
{
"bookId":"123pqr",
"author":"Abc",
"title": "Book1"
"_links": {
"self": {
"href": "http://localhost:port/{bookId}"
}
}
}
More information can be found here
Spring HATEOAS which BTW can also help with building the URI and thus no need to hardcode localhost and port making your app dynamic enough

Not able to post data to server and not geting any respons from server

I am not able to post data to server. On clicking button i submit form and i am getting data into api service class but it's not sending to server which place somewhere else. I am going to give all detail here under:I have other apis method in service class they are working well , but when i want to post data, i am not able to post data and neither getting any response from server while checking database no entry there:
service.ts : orgId is string which is pass in url as foreign key to add adresspostmodel , and data is json object. I am using data:any(reason the actual table has more field which auto generated). when i use postman the api and all working well with same url and json object as i giving hereunder:
service.ts :
public postFormData(orgId: string, data: any): Observable<AdressModel> {
return this.http.post<any>(`${this.ApiUrl}/${orgId}/addresses`, data).pipe(
tap(response => console.log(response)), catchError(this.handleError));
}
onSubmit(){
this.data =
{
"city": "test",
"email": "test#gemiil.com",
"name": "test2",
"recipient": "test",
"street": "test",
"zipCode": "12345"
}
this.ApiService.postFormData(this.organizationId, this.data);
}
this.data actually i am getting data from form, but here form example i am giving you json mock object, which is also correct, here is my json object and whole api in console both api , och json object in console is looking correct for me :
api data in console
{
"city":"test",
"email":"test#gemiil.com",
"name":"test2",
"recipient":"test",
"street":"test",
"zipCode":"12345"
}
Can anyone help to find what's problem is there with logic?
Observable are lazy in nature, so you must subscribe to make it to send request to server.
this.ApiService.postFormData(this.organizationId, this.data).subscribe((resp) => console.log(resp));

Extraction reactions data from facebook via restFb java api?

The new facebook api allows us to get reactions on a post on a page, for this fb has created a reactions edge
I am able to extract data from this edge by simple hitting post-id/reactions from the graph api explorer.
Here is the graph api request :-
1497117777255241_1526440124323006/reactions
and the response data
{ "data": [
{
"id": "100008182891350",
"name": "Harsh Sharma",
"type": "LOVE"
} ], "paging": {
"cursors": {
"before": "TVRBd01EQTRNVGd5T0RreE16VXdPakUwTmpRd01EQTROalk2TnpnNE5qUTRNRE0zT1RFek16RXkZD",
"after": "TVRBd01EQTRNVGd5T0RreE16VXdPakUwTmpRd01EQTROalk2TnpnNE5qUTRNRE0zT1RFek16RXkZD"
} } }
now i try to do the same using the java rest fb api in which I first extract the post and then using that object I call the get reactions method on it but I dont get any data.
Here is the sample code for the same :-
reactionsCount=post.getReactionsCount();
System.out.println("post id-->"+post.getId()+" reactions--->"+post.getReactionsCount());
reactionsObj=post.getReactions();
for the above post id : there is a reaction on it but I am getting the reaction count as zero via restFB, but I am getting data from graph api.
The reactionObj is also null every time (obtained via reactionsObj=post.getReactions();
)
if(reactionsObj!=null)
{
System.out.println("bring it on reactions-------");
for (ReactionItem reactionListItem : reactionsObj.getData())
{
reactionsMap.put("id", reactionListItem.getId());
reactionsMap.put("name", reactionListItem.getName() );
reactionsMap.put("type",reactionListItem.getType() );
}
}
I am getting posts/comments/likes successfully, only the reactions edge is creating problems.
Please let me know where I am going wrong.
Edit
Connection<Post> postSearch =FacebookClientBean.getFacebookclient().fetchConnection(pageId+"/feed", Post.class);
Collected solutions from the comments:
to get reactions on a Post you have to add the field in the request like this:
fetchConnection(pageId+"/feed", Post.class, Parameter.with("fields","reactions.summary(1)"));
An error message with the content requires version v2.6 or higher is a hint the wrong Graph API version is used to request the node.
Select the correct Version in the DefaultFacebookClient constructor:
new DefaultFacebookClient(accessToken, Version.VERSION_2_6);

Comparing two JSON to make sure Key of first json is present in other one

I am writing here to get some clue regarding the problem I'm facing.
I am actually writing a service that will send text messages using some third party API. I've lots of message templates (static text and placeholders for dynamic content) that needs to be sent out and this service will be called from multiple modules with-in my application.
What I've planned is to store message templates in database and once any module require to send text message it will call my messaging service and pass data require to fill up the placeholders for a particular template.
I am saving my templates in database as follows:
{
"data": {
"message": "[GREETING], this is the test message sent on [DATE].",
"constant1": "",
"constant2": ""
},
"metadata": {
"data": {
"message": {
"[GREETING]": "required",
"[DATE]": "required"
},
"constant1": "required",
"constant2": "required",
"constant3": "optional"
}
}
}
data is the actual object I want eventually to pass messaging api and metadata is basically the constants and variables that are required/optional to complete data object.
and the data I'm receiving from other modules that are calling my service is:
{
"[GREETING]": "Dear John Doe",
"[DATE]": "28 February",
"data": {
"constant1": 982042,
"constant2": [64238, 64239]
}
}
So the issue is, I've to verify that all the required constant that are set required in templates metadata should be present the the json I'm receiving while my service is being called. I'm bit confused here of how I can compare the keys of data with template to make sure all the required data of template is sent by the module that has just called my service.
Can someone give me a clue if it's even possible in java ?
p.s: I just want some guidance or clue.
Thanks
Update: if someone have better and neat suggestion in achieving what I want to achieve in above mentioned scenario, please share I would really appreciate that.
Update2: Clarification of what I actually want to achieve: I've a JSON template in which I have a metadata field that tells me which parameters are required to fill up this specific template. So upon receiving call to my service, I've to first check that required parameters (set in metadata of templates) should be there in API request body. Hope that clears my requirements now.

json parser error while making ajax request?

Folks i am getting "parsererror" exception while making ajax request to server.On my dev box
its working fine but at pruction getting this issue for some users(not reproducible at local box)
I did google and found one of the probable cause can be data format mismatch . For example server is
sending jsonp format and client expecting json format or vice versa.But this is not the case with me
becoz its json at both cient and server side.
From serverside struts 2 converts java object(which contains list of map ) in to json string internally.so
I see no scope of error here.
So i suspect there is something in data .for example :=data like scott" but i coud not reproduce issue
even with this kind of data .Can you guys help me to identify what kind of data inside
json can cause this issue/ or it can be a different issue altogether?
$.ajax({
"url": myURL,
"success": function (json) {
},
"dataType": "json",
"cache": false,
"error": function (xhr, error, thrown) {
if (error == "parsererror") {
alert("Getting Error");
}
}
});

Categories