(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"),
|
user=kwargs.get("session_info"),
|
||||||
session_token=inbound_headers.get("X-Session-Token")
|
session_token=inbound_headers.get("X-Session-Token")
|
||||||
)
|
)
|
||||||
|
print("response: ", response)
|
||||||
|
|
||||||
# Note down the results:
|
# Note down the results:
|
||||||
success = response.success
|
success = response.success
|
||||||
@@ -290,7 +291,7 @@ async def authorize_software_client(
|
|||||||
# Done here:
|
# Done here:
|
||||||
return ResponseModel(
|
return ResponseModel(
|
||||||
status_code = StatusCodes.OK if success else StatusCodes.FAILED,
|
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,
|
message = message,
|
||||||
data = {
|
data = {
|
||||||
"client": inbound_data.softwareClient,
|
"client": inbound_data.softwareClient,
|
||||||
|
|||||||
@@ -182,10 +182,12 @@ class PlacesController(GooglePlacesController):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
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:
|
if response.status != 200:
|
||||||
return False
|
return False
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
|
print(data)
|
||||||
# If key invalid, response will contain "error"
|
# If key invalid, response will contain "error"
|
||||||
if "error" in data:
|
if "error" in data:
|
||||||
return False
|
return False
|
||||||
@@ -204,6 +206,8 @@ class PlacesController(GooglePlacesController):
|
|||||||
|
|
||||||
# CHECK -- API KEY IS VALID -
|
# CHECK -- API KEY IS VALID -
|
||||||
valid_api = await PlacesController.is_google_places_api_key_valid(api_key=auth.apiKey)
|
valid_api = await PlacesController.is_google_places_api_key_valid(api_key=auth.apiKey)
|
||||||
|
print(valid_api)
|
||||||
|
|
||||||
if valid_api:
|
if valid_api:
|
||||||
success, object_id = await self.set_token_direct_with_return_id(
|
success, object_id = await self.set_token_direct_with_return_id(
|
||||||
sql_conn=sql_conn,
|
sql_conn=sql_conn,
|
||||||
@@ -229,6 +233,7 @@ class PlacesController(GooglePlacesController):
|
|||||||
display_picture=None,
|
display_picture=None,
|
||||||
session_token=session_token
|
session_token=session_token
|
||||||
)
|
)
|
||||||
|
print(success)
|
||||||
|
|
||||||
# Done here:
|
# Done here:
|
||||||
return PlacesAuthResponse(
|
return PlacesAuthResponse(
|
||||||
@@ -531,4 +536,10 @@ class PlacesController(GooglePlacesController):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
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
|
https://developers.google.com/maps/documentation/places/web-service/text-search
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Ensure that the tokens are valid:
|
print("IN TOKEN", tokens)
|
||||||
await tokens.arefresh(
|
print("IN TOKEN", tokens.model_dump())
|
||||||
http_client=self._http_client,
|
print("IN TOKEN", tokens.token["accessToken"])
|
||||||
client_id=self._client_id,
|
|
||||||
client_secret=self._client_secret,
|
|
||||||
force_refresh=False
|
|
||||||
)
|
|
||||||
|
|
||||||
|
# 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:
|
# Create the headers:
|
||||||
request_headers = {"Authorization": f"Bearer {tokens.accessToken}"}
|
request_headers = {"Authorization": f"Bearer {tokens.token["accessToken"]}"}
|
||||||
if field_mask: request_headers["X-Goog-FieldMask"] = ",".join(field_mask)
|
# 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:
|
# Start creating the JSON payload based on the inputs:
|
||||||
# request_json = {
|
# request_json = {
|
||||||
@@ -710,19 +716,21 @@ class AsyncPlacesClient(AsyncGoogleBase):
|
|||||||
"textQuery": text_query
|
"textQuery": text_query
|
||||||
}
|
}
|
||||||
|
|
||||||
if included_primary_types: request_json["includedPrimaryTypes"] = included_primary_types
|
# if included_primary_types: request_json["includedPrimaryTypes"] = included_primary_types
|
||||||
if included_types: request_json["includedTypes"] = included_types
|
# if included_types: request_json["includedTypes"] = included_types
|
||||||
if excluded_primary_types: request_json["excludedPrimaryTypes"] = excluded_primary_types
|
# if excluded_primary_types: request_json["excludedPrimaryTypes"] = excluded_primary_types
|
||||||
if excluded_types: request_json["excludedTypes"] = excluded_types
|
# if excluded_types: request_json["excludedTypes"] = excluded_types
|
||||||
|
print(request_json)
|
||||||
# Make the API call:
|
# 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(
|
api_response = await self.post(
|
||||||
url=f"https://places.googleapis.com/v1/places:searchText",
|
url=f"https://places.googleapis.com/v1/places:searchText",
|
||||||
headers=request_headers,
|
headers=request_headers,
|
||||||
json=request_json
|
json=request_json
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(api_response)
|
||||||
|
|
||||||
# If the call was successful:
|
# If the call was successful:
|
||||||
if api_response.httpCode in [200]:
|
if api_response.httpCode in [200]:
|
||||||
api_response.success = True
|
api_response.success = True
|
||||||
|
|||||||
Reference in New Issue
Block a user