google places -- autocomplete renturn UNKNOWN_ERROR - google-places-api

Description:
Occasionally, a 500 error will occur on this interface. When I make the request again with the same input parameter, it is normal and cannot be reproduced. The official document does not give an explanation, prompting UNKNOWN_ERROR
api-url: https://maps.googleapis.com/maps/api/place/autocomplete/json
request:
{
"input":"東京灣伊",
"key":"XXXXXX",
"sessiontoken":"ceabe5d0-604d-4273-b8a9-5da90b6b2960",
"location":"22.3193039,114.1693611",
"language":"zh-TW"
}
response rawStatusCode:500
response body:
{
"predictions" : [],
"status" : "UNKNOWN_ERROR"
}
Please help, thanks~

Related

Google Docs API: Image insertion fails with rate limit error

I use the Java Google Drive API to upload a document consisting of text with about 100 images. I produce a request like this:
List<Request> requests = new ArrayList<>();
for (...) {
requests.add(new Request().setInsertText(...));
requests.add(new Request().setInsertInlineImage(...));
}
BatchUpdateDocumentRequest body = new BatchUpdateDocumentRequest().setRequests(requests);
BatchUpdateDocumentResponse response = service.documents().batchUpdate(id, body).execute();
This has worked well for quite a while. However, since today, the tool fails with
com.google.api.client.googleapis.json.GoogleJsonResponseException: 429 Too Many Requests
{
"code" : 429,
"errors" : [ {
"domain" : "global",
"message" : "Resource has been exhausted (e.g. check quota).",
"reason" : "rateLimitExceeded"
} ],
"message" : "Resource has been exhausted (e.g. check quota).",
"status" : "RESOURCE_EXHAUSTED"
}
The quota page shows that I am well within the quota for write requests. And indeed, if I don't include images, I can write additional documents. But as soon as I add a single image, the request fails.
Is there a hidden quota somewhere? Is there a better way to do this?
The problem is in the document that you are using at that moment, try to make a new document, and run the batch update again with the new document id. this would solve the image insertion fail.

What's going on with the Google Knowledge Graph API?

I have used the knowledge graph API before and it worked fine. I tried to access it today and it gives me no results at all. Here is my sample request and response.
GET Request:
https://kgsearch.googleapis.com/v1/entities:search?query=taylor+swift&key=MY_API_KEY&limit=1&indent=True
Response:
{
"#context": {
"#vocab": "http://schema.org/",
"goog": "http://schema.googleapis.com/",
"EntitySearchResult": "goog:EntitySearchResult",
"detailedDescription": "goog:detailedDescription",
"kg": "http://g.co/kg"
},
"#type": "ItemList",
"itemListElement": []
}
It is working now : http://knowledge-graph.fr/
I confirm there was an issue with the API.
You can also try it here in Google Developer Console : https://developers.google.com/apis-explorer/?hl=fr#p/kgsearch/v1/kgsearch.entities.search?query=taylor+swift&_h=1&

Can you change the 401 error response?

My question is, can you change the structure of the response of the 401 error message?
{
"error": "unauthorized",
"error_description": "No AuthenticationProvider found for org.springframework.security.authentication.UsernamePasswordAuthenticationToken"
}
for example
{
"timestamp" : 123124354,
"status" : 401,
"message" : "The username or password are not valid!"
}
This was answered a while ago: Modify default JSON error response from Spring Boot Rest Controller. Checking the reference guide I would recommend going with the #ControllerAdvice to give you the most flexibility on defining how the JSON response is returned.

Elasticsearch GET request with request body

Isn't it against REST-style approach to pass a request body together with GET request?
For instance to filter some information in Elasticsearch
curl localhost:9200/megacorp/employee/_search -d '{"query" : {"filtered" : {"filter" : {"range" : {"age" : { "gt" : 30 }}},"query" : {"match" : {"last_name" : "smith"}}}}}'
some tools are even designed to avoid request body in GET request (like postman)
From the RFC:
A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.
In other words, it's not forbidden, but it's undefined behavior and should be avoided. HTTP clients, servers and proxies are free to drop the body and this would not go against the standard. It's absolutely a bad practice.
Further text from the HTTPBis working group (the group working on HTTP and related standards):
Finally, note that while HTTP allows GET requests to have a body syntactically, this is done only to allow parsers to be generic; as per RFC7231, Section 4.3.1, a body on a GET has no meaning, and will be either ignored or rejected by generic HTTP software.
source
No. It's not.
In REST, using POST to query does not make sense. POST is supposed to modify the server. When searching you obviously don't modify the server.
GET applies here very well.
For example, what would be the difference of running a search with:
GET /_search?q=foo
vs
GET /_search
{
"query": {
"query_string": {
"query" : "foo"
}
}
}
In both cases, you'd like to "GET" back some results. You don't mean to change any state on the server side.
That's why I think GET is totally applicable here wether you are passing the query within the URI or using a body.
That being said, we are aware that some languages and tools don't allow that. Although the RFC does not mention that you can't have a body with GET.
So elasticsearch supports also POST.
This:
curl -XPOST localhost:9200/megacorp/employee/_search -d '{"query" : {"filtered" : {"filter" : {"range" : {"age" : { "gt" : 30 }}},"query" : {"match" : {"last_name" : "smith"}}}}}'
Will work the same way.
You can use query parameter in an ElasticSearch GET request:
just add source=query_string_body&source_content_type='application/json'
The url will look like the following:
http://localhost:9200/index/_search/?source_content_type=application/json&source={"query":{"match_all":{}}}
ref:
https://discuss.elastic.co/t/query-elasticsearch-from-browser-webservice/129697

MailChimp API 3.0 batch request returns 400 Invalid Resource error

I've been trying to use the batch endpoint of MailChimp API (version 3.0) to subscribe new users to a list, but can't make it work.
Here is the request:
POST /3.0/batches
{
"operations": [
{
"method" : "POST",
"path" : "lists/c852ce5c86/members",
"body": "{\"email_address\":\"email#domain.tld\", \"status\":\"subscribed\"}"
}
]
}
The request seems ok cause I get a 200 response:
{
"id": "49abca6ef3",
"status": "finished",
"total_operations": 1,
"finished_operations": 1,
"errored_operations": 1,
"submitted_at": "2015-09-21T18:11:16+00:00",
"completed_at": "2015-09-21T18:11:23+00:00",
"response_body_url": "https://mailchimp-api-batch.s3.amazonaws.com/49abca6ef3-response.tar.gz?..."
}
However, as you can see, the only operation in my batch is errored.
Here is the response_body_url for this operation:
[{
"status_code":400,
"operation_id":null,
"response":"{
\"type\":\"http://kb.mailchimp.com/api/error-docs/400-invalid-resource\",
\"title\":\"Invalid Resource\",
\"status\":400,
\"detail\":\"The resource submitted could not be validated. For field-specific details, see the 'errors' array.\",
\"instance\":\"\",
\"errors\":[{
\"field\":\"\",
\"message\":\"Schema describes object, NULL found instead\"
}]
}"
}]
which is not very helpful :(
Note that if I directly hit POST lists/c852ce5c86/members with {"email_address":"email#domain.tld", "status":"subscribed"} payload, it's working properly.
That was actually a bug in the mailchimp API. After reaching them they quickly fixed it.

Resources