Reputation: 158
I get the error Unknown field for SearchTextRequest: included_fields when trying make a request with client library in Google Places API. There is instruction about how set fieldmask in http requests (https://developers.google.com/maps/documentation/places/web-service/text-search#fieldmask) but I couldn't find instructions for client library.
async def sample_get_place():
# Create a client
client = places_v1.PlacesAsyncClient(client_options={'api_key':api_key.api_key})
# Initialize request argument(s)
request = places_v1.SearchTextRequest(
text_query="restaurants in New York", # Updated query for places in a city
fields=["places.display_name"]
)
# Make the request
response = await client.search_text(request=request)
# Make the request
# response = await client.get_place(request=request)
Upvotes: 0
Views: 22
Reputation: 4865
This is because fields
is not part of the request body, but instead must go in the request headers. As explained in https://googleapis.dev/python/places/latest/places_v1/places.html
Note: every request (except for Autocomplete requests) requires a field mask set outside of the request proto (
all/*
, is not assumed). The field mask can be set via the HTTP headerX-Goog-FieldMask
. See: https://developers.google.com/maps/documentation/places/web-service/choose-fields
To do this, add metadata
when sending the request:
# Make the request with headers.
response = await client.search_text(
request=request,
metadata=[("x-goog-fieldmask","places.id,places.display_name")])
Hopefully this should be easier in the future, if/when https://github.com/googleapis/gapic-generator-python/issues/2054 is implemented.
Upvotes: 0