(20250825) -Added debug print statement for google places api testing.
This commit is contained in:
@@ -268,6 +268,7 @@ async def authorize_software_client(
|
||||
user=kwargs.get("session_info"),
|
||||
session_token=inbound_headers.get("X-Session-Token")
|
||||
)
|
||||
print("response: ", response)
|
||||
|
||||
# Note down the results:
|
||||
success = response.success
|
||||
@@ -290,7 +291,7 @@ async def authorize_software_client(
|
||||
# Done here:
|
||||
return ResponseModel(
|
||||
status_code = StatusCodes.OK if success else StatusCodes.FAILED,
|
||||
http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR,
|
||||
http_code = HttpCodes.SUCCESS if success else HttpCodes.BAD_REQUEST,
|
||||
message = message,
|
||||
data = {
|
||||
"client": inbound_data.softwareClient,
|
||||
|
||||
@@ -182,10 +182,12 @@ class PlacesController(GooglePlacesController):
|
||||
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(url, headers=headers, json=payload, timeout=10) as response:
|
||||
async with session.post(url, headers=headers, json=payload, timeout=30) as response:
|
||||
print(response)
|
||||
if response.status != 200:
|
||||
return False
|
||||
data = await response.json()
|
||||
print(data)
|
||||
# If key invalid, response will contain "error"
|
||||
if "error" in data:
|
||||
return False
|
||||
@@ -204,6 +206,8 @@ class PlacesController(GooglePlacesController):
|
||||
|
||||
# CHECK -- API KEY IS VALID -
|
||||
valid_api = await PlacesController.is_google_places_api_key_valid(api_key=auth.apiKey)
|
||||
print(valid_api)
|
||||
|
||||
if valid_api:
|
||||
success, object_id = await self.set_token_direct_with_return_id(
|
||||
sql_conn=sql_conn,
|
||||
@@ -229,6 +233,7 @@ class PlacesController(GooglePlacesController):
|
||||
display_picture=None,
|
||||
session_token=session_token
|
||||
)
|
||||
print(success)
|
||||
|
||||
# Done here:
|
||||
return PlacesAuthResponse(
|
||||
@@ -531,4 +536,10 @@ class PlacesController(GooglePlacesController):
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
pass
|
||||
async def main():
|
||||
# CHECK -- API KEY IS VALID -
|
||||
valid_api = await PlacesController.is_google_places_api_key_valid(api_key="AIzaSyBsrZ-FtcNVnnZu0V-MpcyncsmMc69zSVY")
|
||||
print(valid_api)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
@@ -678,17 +678,23 @@ class AsyncPlacesClient(AsyncGoogleBase):
|
||||
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
|
||||
)
|
||||
print("IN TOKEN", tokens)
|
||||
print("IN TOKEN", tokens.model_dump())
|
||||
print("IN TOKEN", tokens.token["accessToken"])
|
||||
|
||||
# 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
|
||||
# )
|
||||
print("RH --")
|
||||
# Create the headers:
|
||||
request_headers = {"Authorization": f"Bearer {tokens.accessToken}"}
|
||||
if field_mask: request_headers["X-Goog-FieldMask"] = ",".join(field_mask)
|
||||
request_headers = {"Authorization": f"Bearer {tokens.token["accessToken"]}"}
|
||||
# if field_mask: request_headers["X-Goog-FieldMask"] = ",".join(field_mask)
|
||||
print("RH",request_headers)
|
||||
if field_mask: request_headers["X-Goog-FieldMask"] = "places.displayName,places.formattedAddress,places.priceLevel"
|
||||
|
||||
# Start creating the JSON payload based on the inputs:
|
||||
# request_json = {
|
||||
@@ -710,19 +716,21 @@ class AsyncPlacesClient(AsyncGoogleBase):
|
||||
"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
|
||||
|
||||
# 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
|
||||
print(request_json)
|
||||
# Make the API call:
|
||||
if not self._debug_only_errors: self._printer("Listing Nearby (Radius) Places.")
|
||||
if not self._debug_only_errors: self._printer("Listing text Search Places.")
|
||||
api_response = await self.post(
|
||||
url=f"https://places.googleapis.com/v1/places:searchText",
|
||||
headers=request_headers,
|
||||
json=request_json
|
||||
)
|
||||
|
||||
print(api_response)
|
||||
|
||||
# If the call was successful:
|
||||
if api_response.httpCode in [200]:
|
||||
api_response.success = True
|
||||
|
||||
Reference in New Issue
Block a user