Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL in photo search incorrect #22

Open
pypeaday opened this issue Dec 28, 2024 · 0 comments
Open

URL in photo search incorrect #22

pypeaday opened this issue Dec 28, 2024 · 0 comments

Comments

@pypeaday
Copy link

I'm trying to use this in a webapp I'm building, but I keep getting this "Cannot find Asset" error when searching for photos.

I think this url is backwards per unsplash API docs

url = "/photos/search"

I think a fix would be to update the function as so

    def search(self, query, category=None, orientation=None, page=1, per_page=10):
        """
        Get a single page from a photo search.
        Optionally limit your search to a set of categories by supplying the category ID’s.

        Note: If supplying multiple category ID’s,
        the resulting photos will be those that match all of the given categories,
        not ones that match any category.

        :param query [string]: Search terms.
        :param category [string]: Category ID(‘s) to filter search. If multiple, comma-separated. (deprecated)
        :param orientation [string]: Filter search results by photo orientation.
        Valid values are landscape, portrait, and squarish.
        :param page [integer]: Page number to retrieve. (Optional; default: 1)
        :param per_page [integer]: Number of items per page. (Optional; default: 10)
        :return: [Array]: A single page of the curated Photo list.
        :raise UnsplashError: If the given orientation is not in the default orientation values.
        """
        if orientation and orientation not in self.orientation_values:
            raise Exception()
        params = {
            "query": query,
            "category": category,
            "orientation": orientation,
            "page": page,
            "per_page": per_page
        }
        url = "/search/photos"  # update the URL
        _result = self._get(url, params=params) 
        result = _result.get("results", [])  # returns a dict, so key into what the function would have been expecting
        return PhotoModel.parse_list(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant