diff --git a/rocketapi/instagramapi.py b/rocketapi/instagramapi.py index d482b99..3809a21 100644 --- a/rocketapi/instagramapi.py +++ b/rocketapi/instagramapi.py @@ -26,6 +26,9 @@ def request(self, method, data): self.last_response = response self.counter += 1 if response["status"] == "done": + if method in ["instagram/media/get_shortcode_by_id", "instagram/media/get_id_by_shortcode"]: + return response + if ( response["response"]["status_code"] == 200 and response["response"]["content_type"] == "application/json" @@ -57,16 +60,30 @@ def search(self, query): """ return self.request("instagram/search", {"query": query}) + def get_web_profile_info(self, username): + """ + Retrieve user web profile information by username. + + Args: + username (str): Username + + For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_web_profile_info + """ + return self.request( + "instagram/user/get_web_profile_info", {"username": username} + ) + def get_user_info(self, username): """ Retrieve user information by username. + This is an alias for get_web_profile_info. Args: username (str): Username For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_info """ - return self.request("instagram/user/get_info", {"username": username}) + return self.get_web_profile_info(username) def get_user_info_by_id(self, user_id): """ @@ -97,6 +114,24 @@ def get_user_media(self, user_id, count=12, max_id=None): payload["max_id"] = max_id return self.request("instagram/user/get_media", payload) + def get_user_media_by_username(self, username, count=12, max_id=None): + """ + Retrieve user media by username. + + Args: + username (str): Username + count (int): Number of media to retrieve (max: 12) + max_id (str): Use for pagination + + You can use the `max_id` parameter to paginate through the media (take from the `next_max_id` field of the response). + + For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_media_by_username + """ + payload = {"username": username, "count": count} + if max_id is not None: + payload["max_id"] = max_id + return self.request("instagram/user/get_media_by_username", payload) + def get_user_clips(self, user_id, count=12, max_id=None): """ Retrieve user clips (videos from "Reels" section) by id. @@ -294,24 +329,39 @@ def get_media_info_by_shortcode(self, shortcode): "instagram/media/get_info_by_shortcode", {"shortcode": shortcode} ) - def get_media_likes(self, shortcode, count=12, max_id=None): + def get_media_likes_by_shortcode(self, shortcode): """ Retrieve up to 1000 media likes by media shortcode. Args: shortcode (str): Media shortcode - count (int): Not supported right now - max_id (str): Not supported right now Pagination is not supported for this endpoint. For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_likes """ - payload = {"shortcode": shortcode, "count": count} - if max_id is not None: - payload["max_id"] = max_id + payload = {"shortcode": shortcode} return self.request("instagram/media/get_likes", payload) + def get_media_likes(self, shortcode, count=12, max_id=None): + """ + Retrieve up to 1000 media likes by media shortcode. + This is an alias for get_media_likes_by_shortcode. + + Note: The parameters count and max_id are kept for backward compatibility but are no longer supported. + + Args: + shortcode (str): Media shortcode + count (int): DEPRECATED - No longer supported + max_id (str): DEPRECATED - No longer supported + + Pagination is not supported for this endpoint. + + For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_likes + """ + # Ignoring count and max_id parameters as they're no longer supported + return self.get_media_likes_by_shortcode(shortcode) + def get_media_likes_by_id(self, media_id): """ Retrieve up to 1000 media likes by media id. @@ -434,7 +484,7 @@ def get_hashtag_info(self, name): """ return self.request("instagram/hashtag/get_info", {"name": name}) - def get_hashtag_media(self, name, page=None, max_id=None): + def get_hashtag_media(self, name, page=None, max_id=None, tab=None): """ Retrieve hashtag media by hashtag name. @@ -442,6 +492,7 @@ def get_hashtag_media(self, name, page=None, max_id=None): name (str): Hashtag name page (int): Page number max_id (str): Use for pagination + tab (str): Tab name: recent, top, or clips (default: recent) In order to use pagination, you need to use both the `max_id` and `page` parameters. You can obtain these values from the response's `next_page` and `next_max_id` fields. @@ -452,6 +503,8 @@ def get_hashtag_media(self, name, page=None, max_id=None): payload["page"] = page if max_id is not None: payload["max_id"] = max_id + if tab is not None: + payload["tab"] = tab return self.request("instagram/hashtag/get_media", payload) def get_highlight_stories_bulk(self, highlight_ids): @@ -611,13 +664,19 @@ def search_audios(self, query): """ return self.request("instagram/audio/search", {"query": query}) - def search_clips(self, query): + def search_clips(self, query, max_id=None): """ Search for a specific clip with a caption that includes the query (max 12 results) Args: query (str): The search query + max_id (str): Use for pagination + + You can use the max_id parameter to paginate through following (take from the reels_max_id field of the response). For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/search_clips """ - return self.request("instagram/media/search_clips", {"query": query}) + payload = {"query": query} + if max_id is not None: + payload["max_id"] = max_id + return self.request("instagram/media/search_clips", payload) diff --git a/rocketapi/rocketapi.py b/rocketapi/rocketapi.py index 68ac816..02c776e 100644 --- a/rocketapi/rocketapi.py +++ b/rocketapi/rocketapi.py @@ -11,7 +11,7 @@ def __init__(self, token, max_timeout=30): For more information, see documentation: https://docs.rocketapi.io/api/ """ self.base_url = "https://v1.rocketapi.io/" - self.version = "1.0.10" + self.version = "1.0.12" self.token = token self.max_timeout = max_timeout diff --git a/setup.py b/setup.py index fc632d1..1dbcf2b 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ setuptools.setup( name="rocketapi", - version="1.0.10", + version="1.0.12", author="RocketAPI", author_email="developer@rocketapi.io", description="RocketAPI Python SDK", packages=["rocketapi"], url="https://github.com/rocketapi-io/rocketapi-python", - download_url="https://github.com/rocketapi-io/rocketapi-python/archive/refs/tags/v1.0.10.tar.gz", + download_url="https://github.com/rocketapi-io/rocketapi-python/archive/refs/tags/v1.0.12.tar.gz", install_requires=["requests"], )