(20250730) - ADDED - Google Places API for and paper trading update api with required fies and changes.
This commit is contained in:
@@ -661,6 +661,77 @@ class AsyncPlacesClient(AsyncGoogleBase):
|
||||
return api_response
|
||||
|
||||
|
||||
async def text_query_search(
|
||||
self,
|
||||
tokens: GoogleAuthTokens,
|
||||
text_query: str,
|
||||
included_primary_types: List[str] = None,
|
||||
included_types: List[str] = None,
|
||||
excluded_primary_types: List[str] = None,
|
||||
excluded_types: List[str] = None,
|
||||
field_mask: List[str] = None,
|
||||
max_count: int = 100,
|
||||
next_page_token: str = None,
|
||||
) -> GoogleApiResponse:
|
||||
|
||||
"""
|
||||
https://developers.google.com/maps/documentation/places/web-service/text-search
|
||||
"""
|
||||
|
||||
# Ensure that the tokens are valid:
|
||||
await tokens.arefresh(
|
||||
http_client=self._http_client,
|
||||
client_id=self._client_id,
|
||||
client_secret=self._client_secret,
|
||||
force_refresh=False
|
||||
)
|
||||
|
||||
# Create the headers:
|
||||
request_headers = {"Authorization": f"Bearer {tokens.accessToken}"}
|
||||
if field_mask: request_headers["X-Goog-FieldMask"] = ",".join(field_mask)
|
||||
|
||||
# Start creating the JSON payload based on the inputs:
|
||||
# request_json = {
|
||||
# "maxResultCount": max_count,
|
||||
# "locationRestriction": {
|
||||
# "circle": {
|
||||
# "center": {
|
||||
# "latitude": latitude,
|
||||
# "longitude": longitude
|
||||
# },
|
||||
# "radius": radius
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
|
||||
# Start creating the JSON payload based on the inputs:
|
||||
request_json = {
|
||||
"maxResultCount": max_count,
|
||||
"textQuery": text_query
|
||||
}
|
||||
|
||||
if included_primary_types: request_json["includedPrimaryTypes"] = included_primary_types
|
||||
if included_types: request_json["includedTypes"] = included_types
|
||||
if excluded_primary_types: request_json["excludedPrimaryTypes"] = excluded_primary_types
|
||||
if excluded_types: request_json["excludedTypes"] = excluded_types
|
||||
|
||||
# Make the API call:
|
||||
if not self._debug_only_errors: self._printer("Listing Nearby (Radius) Places.")
|
||||
api_response = await self.post(
|
||||
url=f"https://places.googleapis.com/v1/places:searchText",
|
||||
headers=request_headers,
|
||||
json=request_json
|
||||
)
|
||||
|
||||
# If the call was successful:
|
||||
if api_response.httpCode in [200]:
|
||||
api_response.success = True
|
||||
api_response.data = await api_response.get_json()
|
||||
|
||||
# Done here:
|
||||
return api_response
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** MAIN PROGRAM ***
|
||||
|
||||
Reference in New Issue
Block a user