Google Docs API: Image insertion fails with rate limit error - image

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.

Related

mediaItems missing from Media.ListCustomerMediaItems

When sending the GET request to the following URI
https://mybusiness.googleapis.com/v4/accounts/XXXX/locations/YYYY/media/customers
i get a response that consists of 'nextPageToken' with token for next page, and 'totalMediaItemCount' which says '30' because that's the number of customer media items in the account i use.
According to the docs here:
https://developers.google.com/my-business/reference/rest/v4/accounts.locations.media.customers/list
i am supposed to get this response:
{
"mediaItems": [
{
object (MediaItem)
}
],
"totalMediaItemCount": integer,
"nextPageToken": string
}
but even though it says that i have 30 customer media items, the 'mediaItems' is missing from the response.
is there a problem with the API or am i doing something wrong?

Youtube Data API v3 nextPageToken not working

So I've just started to use the Youtube Data API to get comments from youtube videos. My program has been working until I tried to use the next page token to get more comments. So it first calls the normal URL without the &pageToken=***and then the next time it loops back it calls it with that but returns an error
{
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "invalidPageToken",
"message": "The request specifies an invalid page token.",
"locationType": "parameter",
"location": "pageToken"
}
],
"code": 400,
"message": "The request specifies an invalid page token."
}
}
My program, when calling the first time would get the key returned and save it in a variable for the next time it calls the new url. Yes, I have verified that my variable holds a key. Any help would be greatly appreciated! Thanks in advance :D
You forget playlistId it's required , example :
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=3&playlistId=PLw6Y5u47CYq47oDw63bMqkq06fjuoK_GJ&pageToken=EAAaBlBUOkNBTQ&key=['api_key']&nextPageToken=EAAaBlBUOkNBTQ
take a look on api documentation

Shopify StoreFront API GraphQL query returns nothing

I am trying for a client to build his Shopify store with Gatsby. I use for that gatsby-source-shopify2 plugin, and I always had error messages like that :
{
"errors": [
{
"message": "Cannot query field \"allShopifyProduct\" on type \"Query\".",
"locations": [
{
"line": 2,
"column": 3
}
]
}
]
}
So I investigated a bit to know what was happening, and I went on Shopify help center, followed this quick tuto and reproduced it with my client's store and with my own freshly created free test-store.
Here are the step I followed :
Create a new store, called 'my-store'
Create a new product
Create a new private app
Check the box Allow this app to access your storefront data using the Storefront API
Copy the API key
Double-check that the private app is checked in the Product Availability, just to be sure
Open GraphiQL, and set the GraphQL Endpoint to be https://my-store.myshopify.com/api/graphql
Set the only HTTP Header to be: X-Shopify-Storefront-Access-Token: <API key>
Then I typed in the query field :
{
shop {
name
}
}
And surprisingly, no error happened, but the expected output didn't come. It should have been :
{
"data": {
"shop": {
"name": "my-store",
}
}
}
I tried in gatsby too, and the same errors came again, obviously.
What is wrong with me ?
OK, my mistake, I went to fast : in the private app you have many keys : <API key>, <shared secret> and <API Storefront access token>. I used the <API key> instead of the <API Storefront access token>. Now everything is OK...

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

Google place api - application specific search

I am trying to do application specific places search with google place api. Here is how I am adding a place:
Request:
{
"location": {
"lat": 37.760538,
"lng": -121.900879
},
"accuracy": 50,
"name": "p2p",
"types": ["other"]
}
I get success response as shown below:
Response:
{
"id" : "dfe583b1ac058750cf524f958afc5e82ade455d7",
"place_id" : "qgYvCi0wMDAwMDBhNWE4OWU4NTMzOjgwOGZlZTBhNjI3OjBjNTU1OTU4M2Q2NDI5YmM",
"reference" : "CkQxAAAAsPE72V-jhHUjj6vPy2HdC__2MhAdXanL6mlFBA4bcayRabKyMlfKFiah7U2vkoCj1P_0w9ESFSv5mfDkyufaZhIQTHBHY_jPGRHEE3EmEAGElhoUXTSylMslwHSTK5tYdstW2rOZKbw",
"scope" : "APP",
"status" : "OK"
}
When I search for this place using radar search, I get ZERO_RESULTS.
Request:
https://maps.googleapis.com/maps/api/place/radarsearch/json?key=key&radius=5000&location=37.761926,-121.891856&keyword=p2p
Response:
{
"html_attributions": [ ],
"results": [ ],
"status": "ZERO_RESULTS"
}
Is there something that I am doing the right way? Please help.
Thanks & Regards,
--Rajani
Your scope is "APP". That means you can access it (via PlaceID) from the application that created the entry only. If the location passes Google's moderation process, then it will gain scope "GOOGLE" and be accessible from the general searches.
scope — Indicates the scope of the place_id. The possible values are:
APP: The place ID is recognised by your application only. This is because your
application added the place, and the place has not yet
passed the moderation process.
GOOGLE: The place ID is available to other applications and on Google Maps.
Note: The scope field is included only in Nearby Search results and
Place Details results. You can only retrieve app-scoped places via the
Nearby Search and the Place Details requests. If the scope field is
not present in a response, it is safe to assume the scope is GOOGLE.
See: https://developers.google.com/places/documentation/search

Resources