From 9c5fd968024bef57777909faf32011247de51798 Mon Sep 17 00:00:00 2001 From: RocketAPI Date: Mon, 10 Jul 2023 20:45:35 +0300 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=94=A5=20Threads=20API=20added,=201.0?= =?UTF-8?q?.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples_threads.py | 14 +++ rocketapi/__init__.py | 1 + rocketapi/instagramapi.py | 5 +- rocketapi/rocketapi.py | 4 +- rocketapi/threadsapi.py | 185 ++++++++++++++++++++++++++++++++++++++ setup.py | 4 +- 6 files changed, 205 insertions(+), 8 deletions(-) create mode 100644 examples_threads.py create mode 100644 rocketapi/threadsapi.py diff --git a/examples_threads.py b/examples_threads.py new file mode 100644 index 0000000..ee33aaa --- /dev/null +++ b/examples_threads.py @@ -0,0 +1,14 @@ +from rocketapi import ThreadsAPI +from rocketapi.exceptions import NotFoundException, BadResponseException + +api = ThreadsAPI(token="put your token here") + +# Get user feed by id +user_id = 35670846775 +try: + user = api.get_user_feed(user_id) + print(user) +except NotFoundException: + print(f"User {user_id} not found") +except BadResponseException: + print(f"Can't get {user_id} feed from API") diff --git a/rocketapi/__init__.py b/rocketapi/__init__.py index ecf79a2..f3fc4f1 100644 --- a/rocketapi/__init__.py +++ b/rocketapi/__init__.py @@ -1 +1,2 @@ from .instagramapi import InstagramAPI +from .threadsapi import ThreadsAPI diff --git a/rocketapi/instagramapi.py b/rocketapi/instagramapi.py index d141bfa..cf8b55d 100644 --- a/rocketapi/instagramapi.py +++ b/rocketapi/instagramapi.py @@ -3,13 +3,12 @@ class InstagramAPI(RocketAPI): - def __init__(self, token, threads=1, max_timeout=30): + def __init__(self, token, max_timeout=30): """ Instagram API client. Args: token (str): Your RocketAPI token (https://rocketapi.io/dashboard/) - threads (int): Number of threads to use for requests (it's beta, use with caution, every thread charges 1 request) max_timeout (int): Maximum timeout for requests. Please, don't use values lower than 15 seconds, it may cause problems with API. For debugging purposes you can use the following variables: @@ -20,7 +19,7 @@ def __init__(self, token, threads=1, max_timeout=30): """ self.last_response = None self.counter = 0 - super().__init__(token, threads=threads, max_timeout=max_timeout) + super().__init__(token, max_timeout=max_timeout) def request(self, method, data): response = super().request(method, data) diff --git a/rocketapi/rocketapi.py b/rocketapi/rocketapi.py index 5f1db31..8edd35a 100644 --- a/rocketapi/rocketapi.py +++ b/rocketapi/rocketapi.py @@ -2,7 +2,7 @@ class RocketAPI: - def __init__(self, token, threads=1, max_timeout=30): + def __init__(self, token, max_timeout=30): """ RocketAPI client. @@ -12,11 +12,9 @@ def __init__(self, token, threads=1, max_timeout=30): """ self.base_url = "https://v1.rocketapi.io/" self.token = token - self.threads = threads self.max_timeout = max_timeout def request(self, method, data): - data["_threads"] = self.threads return requests.post( url=self.base_url + method, json=data, diff --git a/rocketapi/threadsapi.py b/rocketapi/threadsapi.py new file mode 100644 index 0000000..d281e8b --- /dev/null +++ b/rocketapi/threadsapi.py @@ -0,0 +1,185 @@ +from rocketapi.exceptions import NotFoundException, BadResponseException +from rocketapi.rocketapi import RocketAPI + + +class ThreadsAPI(RocketAPI): + def __init__(self, token, max_timeout=30): + """ + Threads API client. + + Args: + token (str): Your RocketAPI token (https://rocketapi.io/dashboard/) + max_timeout (int): Maximum timeout for requests. Please, don't use values lower than 15 seconds, it may cause problems with API. + + For debugging purposes you can use the following variables: + last_response (dict): contains the last response from the API. + counter (int): contains the number of requests made in the current session. + + For more information, see documentation: https://docs.rocketapi.io/api/ + """ + self.last_response = None + self.counter = 0 + super().__init__(token, max_timeout=max_timeout) + + def request(self, method, data): + response = super().request(method, data) + self.last_response = response + self.counter += 1 + if response["status"] == "done": + if ( + response["response"]["status_code"] == 200 + and response["response"]["content_type"] == "application/json" + ): + return response["response"]["body"] + elif response["response"]["status_code"] == 404: + raise NotFoundException("Instagram resource not found") + else: + raise BadResponseException("Bad response from Threads") + raise BadResponseException("Bad response from RocketAPI") + + def search_users(self, query): + """ + Search for a specific user in Threads + + Args: + query (str): Username to search for + + For more information, see documentation: https://docs.rocketapi.io/api/threads/search_users + """ + return self.request("threads/search_users", {"query": query}) + + def get_user_info(self, user_id): + """ + Retrieve Threads user information by id. + + Args: + user_id (int): User id + + For more information, see documentation: https://docs.rocketapi.io/api/threads/user/get_info + """ + return self.request("threads/user/get_info", {"id": user_id}) + + def get_user_feed(self, user_id, max_id=None): + """ + Retrieve Threads user feed by id. + + Args: + user_id (int): User id + 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/threads/user/get_feed + """ + payload = {"id": user_id} + if max_id is not None: + payload["max_id"] = max_id + return self.request("threads/user/get_feed", payload) + + def get_user_replies(self, user_id, max_id=None): + """ + Retrieve Threads user replies by id. + + Args: + user_id (int): User id + 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/threads/user/get_replies + """ + payload = {"id": user_id} + if max_id is not None: + payload["max_id"] = max_id + return self.request("threads/user/get_replies", payload) + + def get_user_followers(self, user_id, max_id=None): + """ + Retrieve Threads user followers by id. + + Args: + user_id (int): User id + max_id (str): Use for pagination + + You can use the `max_id` parameter to paginate through followers (take from the `next_max_id` field of the response). + + For more information, see documentation: https://docs.rocketapi.io/api/threads/user/get_followers + """ + payload = {"id": user_id} + if max_id is not None: + payload["max_id"] = max_id + return self.request("threads/user/get_followers", payload) + + def search_user_followers(self, user_id, query): + """ + Search Threads user followers by user id. + + Args: + user_id (int): User id + query (str): Search query + + For more information, see documentation: https://docs.rocketapi.io/api/threads/user/get_followers + """ + return self.request( + "threads/user/get_followers", {"id": user_id, "query": query} + ) + + def get_user_following(self, user_id, max_id=None): + """ + Retrieve Threads user following by id. + + Args: + user_id (int): User id + max_id (str): Use for pagination + + You can use the `max_id` parameter to paginate through followers (take from the `next_max_id` field of the response). + + For more information, see documentation: https://docs.rocketapi.io/api/threads/user/get_following + """ + payload = {"id": user_id} + if max_id is not None: + payload["max_id"] = max_id + return self.request("threads/user/get_following", payload) + + def search_user_following(self, user_id, query): + """ + Search Threads user following by user id. + + Args: + user_id (int): User id + query (str): Search query + + For more information, see documentation: https://docs.rocketapi.io/api/threads/user/get_following + """ + return self.request( + "threads/user/get_following", {"id": user_id, "query": query} + ) + + def get_thread_replies(self, thread_id, max_id=None): + """ + Retrieve thread replies by id. + + Args: + thread_id (int): Thread id + max_id (str): Use for pagination + + You can use the `max_id` parameter to paginate through the media (take from the `paging_tokens["downwards"]` field of the response). + + For more information, see documentation: https://docs.rocketapi.io/api/threads/thread/get_replies + """ + payload = {"id": thread_id} + if max_id is not None: + payload["max_id"] = max_id + return self.request("threads/thread/get_replies", payload) + + def get_thread_likes(self, thread_id): + """ + Retrieve thread likes by id. + + Args: + thread_id (int): Thread id + + For more information, see documentation: https://docs.rocketapi.io/api/threads/thread/get_likes + """ + payload = {"id": thread_id} + return self.request("threads/thread/get_likes", payload) diff --git a/setup.py b/setup.py index 4063754..29a2abe 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ setuptools.setup( name="rocketapi", - version="1.0.4", + version="1.0.5", 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.4.tar.gz", + download_url="https://github.com/rocketapi-io/rocketapi-python/archive/refs/tags/v1.0.5.tar.gz", install_requires=["requests"], ) From 4c502a4c05a672722906285c92752daaae1c82fb Mon Sep 17 00:00:00 2001 From: RocketAPI Date: Fri, 13 Oct 2023 21:14:29 +0300 Subject: [PATCH 2/8] 1.0.6 --- rocketapi/instagramapi.py | 5 +++-- setup.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/rocketapi/instagramapi.py b/rocketapi/instagramapi.py index cf8b55d..272c9e4 100644 --- a/rocketapi/instagramapi.py +++ b/rocketapi/instagramapi.py @@ -88,19 +88,20 @@ 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_clips(self, user_id, max_id=None): + def get_user_clips(self, user_id, count=12, max_id=None): """ Retrieve user clips (videos from "Reels" section) by id. Args: user_id (int): User id + count (int): Number of media to retrieve (max: 50) max_id (str): Use for pagination You can use the `max_id` parameter to paginate through the media (take from the `max_id` (!) field of the response). For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_clips """ - payload = {"id": user_id} + payload = {"id": user_id, "count": count} if max_id is not None: payload["max_id"] = max_id return self.request("instagram/user/get_clips", payload) diff --git a/setup.py b/setup.py index 29a2abe..e66fc63 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ setuptools.setup( name="rocketapi", - version="1.0.5", + version="1.0.6", 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.5.tar.gz", + download_url="https://github.com/rocketapi-io/rocketapi-python/archive/refs/tags/v1.0.6.tar.gz", install_requires=["requests"], ) From 3655bde9a73673c4a6b0ef103f45c04a31a085b8 Mon Sep 17 00:00:00 2001 From: RocketAPI Date: Fri, 20 Sep 2024 15:00:15 +0500 Subject: [PATCH 3/8] 1.0.7 --- rocketapi/instagramapi.py | 68 ++++++++++++++++++++++++++++++++++----- setup.py | 4 +-- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/rocketapi/instagramapi.py b/rocketapi/instagramapi.py index 272c9e4..faa500e 100644 --- a/rocketapi/instagramapi.py +++ b/rocketapi/instagramapi.py @@ -34,13 +34,21 @@ def request(self, method, data): elif response["response"]["status_code"] == 404: raise NotFoundException("Instagram resource not found") else: - raise BadResponseException("Bad response from Instagram") - raise BadResponseException("Bad response from RocketAPI") + raise BadResponseException( + f"Bad response from Instagram ({method}: {response['response']['status_code']})" + ) + raise BadResponseException(f"Bad response from RocketAPI ({method})") def search(self, query): """ Search for a specific user, hashtag or place. + As of September 2024, we no longer recommend using this method, as it now only returns a maximum of 5 users and leaves the places and hashtags arrays empty. Instead, please use the separate methods: + - `search_users` + - `search_hashtags` + - `search_locations` + - `search_audios` + Args: query (str): The search query @@ -76,7 +84,7 @@ def get_user_media(self, user_id, count=12, max_id=None): Args: user_id (int): User id - count (int): Number of media to retrieve (max: 50) + 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). @@ -179,7 +187,7 @@ def get_user_followers(self, user_id, count=12, max_id=None): Args: user_id (int): User id - count (int): Number of users to return (max: 100) + count (int): Number of users to return (max: 50) max_id (str): Use for pagination You can use the `max_id` parameter to paginate through followers (take from the `next_max_id` field of the response). @@ -287,14 +295,14 @@ def get_media_info_by_shortcode(self, shortcode): def get_media_likes(self, shortcode, count=12, max_id=None): """ - Retrieve media likes by media shortcode. + Retrieve up to 1000 media likes by media shortcode. Args: shortcode (str): Media shortcode - count (int): Number of likers to return (max: 50) - max_id (str): Use for pagination + count (int): Not supported right now + max_id (str): Not supported right now - You can use the `max_id` parameter to paginate through likers (take from the `next_max_id` field of the response). + Pagination is not supported for this endpoint. For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_likes """ @@ -505,3 +513,47 @@ def get_user_about(self, user_id): For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_about """ return self.request("instagram/user/get_about", {"id": user_id}) + + def search_users(self, query): + """ + Search for a specific user (max 50 results) + + Args: + query (str): The search query + + For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/search + """ + return self.request("instagram/user/search", {"query": query}) + + def search_hashtags(self, query): + """ + Search for a specific hashtag (max 20 results) + + Args: + query (str): The search query + + For more information, see documentation: https://docs.rocketapi.io/api/instagram/hashtag/search + """ + return self.request("instagram/hashtag/search", {"query": query}) + + def search_locations(self, query): + """ + Search for a specific location (max 20 results) + + Args: + query (str): The search query + + For more information, see documentation: https://docs.rocketapi.io/api/instagram/location/search + """ + return self.request("instagram/location/search", {"query": query}) + + def search_audios(self, query): + """ + Search for a specific audio (max 10 results) + + Args: + query (str): The search query + + For more information, see documentation: https://docs.rocketapi.io/api/instagram/audio/search + """ + return self.request("instagram/audio/search", {"query": query}) diff --git a/setup.py b/setup.py index e66fc63..d8ab8c7 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ setuptools.setup( name="rocketapi", - version="1.0.6", + version="1.0.7", 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.6.tar.gz", + download_url="https://github.com/rocketapi-io/rocketapi-python/archive/refs/tags/v1.0.7.tar.gz", install_requires=["requests"], ) From a139016919d7bf424a9742e607268de5795490c1 Mon Sep 17 00:00:00 2001 From: RocketAPI Date: Thu, 24 Oct 2024 12:12:36 +0500 Subject: [PATCH 4/8] 1.0.8 --- rocketapi/instagramapi.py | 36 ++++++++++++++++++++++++++++++++++-- rocketapi/rocketapi.py | 6 +++++- setup.py | 4 ++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/rocketapi/instagramapi.py b/rocketapi/instagramapi.py index faa500e..a327b35 100644 --- a/rocketapi/instagramapi.py +++ b/rocketapi/instagramapi.py @@ -48,6 +48,7 @@ def search(self, query): - `search_hashtags` - `search_locations` - `search_audios` + - `search_clips` Args: query (str): The search query @@ -102,7 +103,7 @@ def get_user_clips(self, user_id, count=12, max_id=None): Args: user_id (int): User id - count (int): Number of media to retrieve (max: 50) + 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 `max_id` (!) field of the response). @@ -375,7 +376,7 @@ def get_location_info(self, location_id): """ return self.request("instagram/location/get_info", {"id": location_id}) - def get_location_media(self, location_id, page=None, max_id=None): + def get_location_media(self, location_id, page=None, max_id=None, tab=None): """ Retrieve location media by location id. @@ -383,6 +384,7 @@ def get_location_media(self, location_id, page=None, max_id=None): location_id (int): Location id page (int): Page number max_id (str): Use for pagination + tab (str): Tab name: recent, ranked (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. @@ -393,6 +395,8 @@ def get_location_media(self, location_id, 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/location/get_media", payload) def get_hashtag_info(self, name): @@ -500,6 +504,23 @@ def get_audio_media(self, audio_id, max_id=None): payload["max_id"] = max_id return self.request("instagram/audio/get_media", payload) + def get_audio_media_by_canonical_id(self, audio_canonical_id, max_id=None): + """ + Retrieve audio media by audio canonical id. + + Args: + audio_canonical_id (int): Audio canonical id + max_id (str): Use for pagination + + You can use the `max_id` parameter to paginate through media (take from the `next_max_id` field of the response). + + For more information, see documentation: https://docs.rocketapi.io/api/instagram/audio/get_media_by_canonical_id + """ + payload = {"id": audio_canonical_id} + if max_id is not None: + payload["max_id"] = max_id + return self.request("instagram/audio/get_media_by_canonical_id", payload) + def get_user_about(self, user_id): """ Obtain user details from «About this Account» section. @@ -557,3 +578,14 @@ def search_audios(self, query): For more information, see documentation: https://docs.rocketapi.io/api/instagram/audio/search """ return self.request("instagram/audio/search", {"query": query}) + + def search_clips(self, query): + """ + Search for a specific clip with a caption that includes the query (max 12 results) + + Args: + query (str): The search query + + For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/search_clips + """ + return self.request("instagram/media/search_clips", {"query": query}) diff --git a/rocketapi/rocketapi.py b/rocketapi/rocketapi.py index 8edd35a..106678e 100644 --- a/rocketapi/rocketapi.py +++ b/rocketapi/rocketapi.py @@ -11,6 +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.8" self.token = token self.max_timeout = max_timeout @@ -18,6 +19,9 @@ def request(self, method, data): return requests.post( url=self.base_url + method, json=data, - headers={"Authorization": f"Token {self.token}"}, + headers={ + "Authorization": f"Token {self.token}", + "User-Agent": f"RocketAPI Python SDK/{self.version}", + }, timeout=self.max_timeout, ).json() diff --git a/setup.py b/setup.py index d8ab8c7..2ed5407 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ setuptools.setup( name="rocketapi", - version="1.0.7", + version="1.0.8", 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.7.tar.gz", + download_url="https://github.com/rocketapi-io/rocketapi-python/archive/refs/tags/v1.0.8.tar.gz", install_requires=["requests"], ) From ef72b4f495f757bd39078bb3ccedcd90cb081ed3 Mon Sep 17 00:00:00 2001 From: RocketAPI Date: Tue, 26 Nov 2024 21:31:27 +0300 Subject: [PATCH 5/8] 1.0.9 --- rocketapi/instagramapi.py | 27 ++++++++++++++++++++++++--- rocketapi/rocketapi.py | 2 +- setup.py | 4 ++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/rocketapi/instagramapi.py b/rocketapi/instagramapi.py index a327b35..ef2689d 100644 --- a/rocketapi/instagramapi.py +++ b/rocketapi/instagramapi.py @@ -312,6 +312,19 @@ def get_media_likes(self, shortcode, count=12, max_id=None): payload["max_id"] = max_id return self.request("instagram/media/get_likes", payload) + def get_media_likes_by_id(self, media_id): + """ + Retrieve up to 1000 media likes by media id. + + Args: + media_id (int): Media id + + Pagination is not supported for this endpoint. + + For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_likes_by_id + """ + return self.request("instagram/media/get_likes_by_id", {"id": media_id}) + def get_media_comments(self, media_id, can_support_threading=True, min_id=None): """ Retrieve media comments by media id. @@ -521,13 +534,21 @@ def get_audio_media_by_canonical_id(self, audio_canonical_id, max_id=None): payload["max_id"] = max_id return self.request("instagram/audio/get_media_by_canonical_id", payload) + def get_live_info(self, broadcast_id): + """ + Retrieve live information by broadcast id. + + Args: + broadcast_id (int): Broadcast id + + For more information, see documentation: https://docs.rocketapi.io/api/instagram/live/get_info + """ + return self.request("instagram/live/get_info", {"id": broadcast_id}) + def get_user_about(self, user_id): """ Obtain user details from «About this Account» section. - ⭐️ This method is exclusively available to our Enterprise+ clients. - If you wish to enable it for your account, please get in touch with our support team: https://t.me/rocketapi - Args: user_id (int): User id diff --git a/rocketapi/rocketapi.py b/rocketapi/rocketapi.py index 106678e..6fcafd9 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.8" + self.version = "1.0.9" self.token = token self.max_timeout = max_timeout diff --git a/setup.py b/setup.py index 2ed5407..04b9e9b 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ setuptools.setup( name="rocketapi", - version="1.0.8", + version="1.0.9", 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.8.tar.gz", + download_url="https://github.com/rocketapi-io/rocketapi-python/archive/refs/tags/v1.0.9.tar.gz", install_requires=["requests"], ) From 61d7d342dd74f00022f59ec66b2a3f8579d20181 Mon Sep 17 00:00:00 2001 From: RocketAPI Date: Wed, 11 Dec 2024 19:57:42 +0300 Subject: [PATCH 6/8] 1.0.10 --- rocketapi/instagramapi.py | 11 +++++++++++ rocketapi/rocketapi.py | 2 +- setup.py | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/rocketapi/instagramapi.py b/rocketapi/instagramapi.py index ef2689d..d482b99 100644 --- a/rocketapi/instagramapi.py +++ b/rocketapi/instagramapi.py @@ -367,6 +367,17 @@ def get_media_id_by_shortcode(self, shortcode): "instagram/media/get_id_by_shortcode", {"shortcode": shortcode} ) + def get_media_id_by_share(self, share): + """ + Get media id by share code (for links like https://www.instagram.com/share/XXXxx356, where XXXxx356 is the share code). + + Args: + share (str): Share code + + For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_id_by_share + """ + return self.request("instagram/media/get_id_by_share", {"share": share}) + def get_guide_info(self, guide_id): """ Retrieve guide information by guide id. diff --git a/rocketapi/rocketapi.py b/rocketapi/rocketapi.py index 6fcafd9..68ac816 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.9" + self.version = "1.0.10" self.token = token self.max_timeout = max_timeout diff --git a/setup.py b/setup.py index 04b9e9b..fc632d1 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ setuptools.setup( name="rocketapi", - version="1.0.9", + version="1.0.10", 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.9.tar.gz", + download_url="https://github.com/rocketapi-io/rocketapi-python/archive/refs/tags/v1.0.10.tar.gz", install_requires=["requests"], ) From 23ada9f4af7df388b52343509cf7e4df45023446 Mon Sep 17 00:00:00 2001 From: RocketAPI Date: Tue, 22 Apr 2025 12:10:20 +0400 Subject: [PATCH 7/8] 1.0.11 --- rocketapi/instagramapi.py | 76 +++++++++++++++++++++++++++++++++------ rocketapi/rocketapi.py | 2 +- setup.py | 4 +-- 3 files changed, 69 insertions(+), 13 deletions(-) diff --git a/rocketapi/instagramapi.py b/rocketapi/instagramapi.py index d482b99..6aafc78 100644 --- a/rocketapi/instagramapi.py +++ b/rocketapi/instagramapi.py @@ -57,16 +57,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 +111,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 +326,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 +481,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 +489,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 +500,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 +661,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..fc39713 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.11" self.token = token self.max_timeout = max_timeout diff --git a/setup.py b/setup.py index fc632d1..278e000 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ setuptools.setup( name="rocketapi", - version="1.0.10", + version="1.0.11", 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.11.tar.gz", install_requires=["requests"], ) From 2188d7660350e9bea52c62d0c6d2252e8773bb9b Mon Sep 17 00:00:00 2001 From: RocketAPI Date: Tue, 22 Apr 2025 19:56:06 +0400 Subject: [PATCH 8/8] 1.0.12 --- rocketapi/instagramapi.py | 3 +++ rocketapi/rocketapi.py | 2 +- setup.py | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/rocketapi/instagramapi.py b/rocketapi/instagramapi.py index 6aafc78..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" diff --git a/rocketapi/rocketapi.py b/rocketapi/rocketapi.py index fc39713..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.11" + self.version = "1.0.12" self.token = token self.max_timeout = max_timeout diff --git a/setup.py b/setup.py index 278e000..1dbcf2b 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ setuptools.setup( name="rocketapi", - version="1.0.11", + 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.11.tar.gz", + download_url="https://github.com/rocketapi-io/rocketapi-python/archive/refs/tags/v1.0.12.tar.gz", install_requires=["requests"], )