slidedeckai.helpers.image_search.search_pexels#
- slidedeckai.helpers.image_search.search_pexels(query: str, size: Literal['small', 'medium', 'large'] = 'medium', per_page: int = 3) dict[source]#
Searches for images on Pexels using the provided query.
This function sends a GET request to the Pexels API with the specified search query and authorization header containing the API key. It returns the JSON response from the API.
[2024-08-31] Note: curl succeeds but API call via Python requests fail. Apparently, this could be due to Cloudflare (or others) blocking the requests, perhaps identifying as Web-scraping. So, changing the user-agent to Firefox. https://stackoverflow.com/a/74674276/147021 https://stackoverflow.com/a/51268523/147021 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox#linux
- Parameters:
query – The search query for finding images.
size – The size of the images: small, medium, or large.
per_page – No. of results to be displayed per page.
- Returns:
The JSON response from the Pexels API containing search results. Empty dict if API key is not set.
- Raises:
requests.exceptions.RequestException – If the request to the Pexels API fails.