Skip to content

URL in photo search incorrect #22

Open

Description

@pypeaday

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions