├── .gitignore ├── README.md ├── examples.py ├── examples_threads.py ├── license.txt ├── rocketapi ├── __init__.py ├── exceptions.py ├── instagramapi.py ├── rocketapi.py └── threadsapi.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | .idea/ 161 | 162 | .DS_Store 163 | .pre-commit-config.yaml 164 | pyproject.toml 165 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | 3 | This library provides a pure Python interface for the RocketAPI. It's compatible with Python versions **3.7+**. 4 | 5 | ## Installing 6 | 7 | You can install or upgrade `rocketapi` via 8 | 9 | ```bash 10 | pip install rocketapi --upgrade 11 | ``` 12 | 13 | ## Usage 14 | 15 | See the [documentation](https://docs.rocketapi.io) for more information. 16 | -------------------------------------------------------------------------------- /examples.py: -------------------------------------------------------------------------------- 1 | from rocketapi import InstagramAPI 2 | from rocketapi.exceptions import NotFoundException, BadResponseException 3 | 4 | api = InstagramAPI(token="put your token here") 5 | 6 | # Get user info by username 7 | username = "kanyewest" 8 | try: 9 | user = api.get_user_info(username) 10 | print(user) 11 | except NotFoundException: 12 | print(f"User {username} not found") 13 | except BadResponseException: 14 | print(f"Can't get {username} info from API") 15 | -------------------------------------------------------------------------------- /examples_threads.py: -------------------------------------------------------------------------------- 1 | from rocketapi import ThreadsAPI 2 | from rocketapi.exceptions import NotFoundException, BadResponseException 3 | 4 | api = ThreadsAPI(token="put your token here") 5 | 6 | # Get user feed by id 7 | user_id = 35670846775 8 | try: 9 | user = api.get_user_feed(user_id) 10 | print(user) 11 | except NotFoundException: 12 | print(f"User {user_id} not found") 13 | except BadResponseException: 14 | print(f"Can't get {user_id} feed from API") 15 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 rocketapi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /rocketapi/__init__.py: -------------------------------------------------------------------------------- 1 | from .instagramapi import InstagramAPI 2 | from .threadsapi import ThreadsAPI 3 | -------------------------------------------------------------------------------- /rocketapi/exceptions.py: -------------------------------------------------------------------------------- 1 | class NotFoundException(Exception): 2 | pass 3 | 4 | 5 | class BadResponseException(Exception): 6 | pass 7 | -------------------------------------------------------------------------------- /rocketapi/instagramapi.py: -------------------------------------------------------------------------------- 1 | from rocketapi.exceptions import NotFoundException, BadResponseException 2 | from rocketapi.rocketapi import RocketAPI 3 | 4 | 5 | class InstagramAPI(RocketAPI): 6 | def __init__(self, token, max_timeout=30): 7 | """ 8 | Instagram API client. 9 | 10 | Args: 11 | token (str): Your RocketAPI token (https://rocketapi.io/dashboard/) 12 | max_timeout (int): Maximum timeout for requests. Please, don't use values lower than 15 seconds, it may cause problems with API. 13 | 14 | For debugging purposes you can use the following variables: 15 | last_response (dict): contains the last response from the API. 16 | counter (int): contains the number of requests made in the current session. 17 | 18 | For more information, see documentation: https://docs.rocketapi.io/api/ 19 | """ 20 | self.last_response = None 21 | self.counter = 0 22 | super().__init__(token, max_timeout=max_timeout) 23 | 24 | def request(self, method, data): 25 | response = super().request(method, data) 26 | self.last_response = response 27 | self.counter += 1 28 | if response["status"] == "done": 29 | if method in ["instagram/media/get_shortcode_by_id", "instagram/media/get_id_by_shortcode"]: 30 | return response 31 | 32 | if ( 33 | response["response"]["status_code"] == 200 34 | and response["response"]["content_type"] == "application/json" 35 | ): 36 | return response["response"]["body"] 37 | elif response["response"]["status_code"] == 404: 38 | raise NotFoundException("Instagram resource not found") 39 | else: 40 | raise BadResponseException( 41 | f"Bad response from Instagram ({method}: {response['response']['status_code']})" 42 | ) 43 | raise BadResponseException(f"Bad response from RocketAPI ({method})") 44 | 45 | def search(self, query): 46 | """ 47 | Search for a specific user, hashtag or place. 48 | 49 | 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: 50 | - `search_users` 51 | - `search_hashtags` 52 | - `search_locations` 53 | - `search_audios` 54 | - `search_clips` 55 | 56 | Args: 57 | query (str): The search query 58 | 59 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/search 60 | """ 61 | return self.request("instagram/search", {"query": query}) 62 | 63 | def get_web_profile_info(self, username): 64 | """ 65 | Retrieve user web profile information by username. 66 | 67 | Args: 68 | username (str): Username 69 | 70 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_web_profile_info 71 | """ 72 | return self.request( 73 | "instagram/user/get_web_profile_info", {"username": username} 74 | ) 75 | 76 | def get_user_info(self, username): 77 | """ 78 | Retrieve user information by username. 79 | This is an alias for get_web_profile_info. 80 | 81 | Args: 82 | username (str): Username 83 | 84 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_info 85 | """ 86 | return self.get_web_profile_info(username) 87 | 88 | def get_user_info_by_id(self, user_id): 89 | """ 90 | Retrieve user information by id. 91 | 92 | Args: 93 | user_id (int): User id 94 | 95 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_info_by_id 96 | """ 97 | return self.request("instagram/user/get_info_by_id", {"id": user_id}) 98 | 99 | def get_user_media(self, user_id, count=12, max_id=None): 100 | """ 101 | Retrieve user media by id. 102 | 103 | Args: 104 | user_id (int): User id 105 | count (int): Number of media to retrieve (max: 12) 106 | max_id (str): Use for pagination 107 | 108 | You can use the `max_id` parameter to paginate through the media (take from the `next_max_id` field of the response). 109 | 110 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_media 111 | """ 112 | payload = {"id": user_id, "count": count} 113 | if max_id is not None: 114 | payload["max_id"] = max_id 115 | return self.request("instagram/user/get_media", payload) 116 | 117 | def get_user_media_by_username(self, username, count=12, max_id=None): 118 | """ 119 | Retrieve user media by username. 120 | 121 | Args: 122 | username (str): Username 123 | count (int): Number of media to retrieve (max: 12) 124 | max_id (str): Use for pagination 125 | 126 | You can use the `max_id` parameter to paginate through the media (take from the `next_max_id` field of the response). 127 | 128 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_media_by_username 129 | """ 130 | payload = {"username": username, "count": count} 131 | if max_id is not None: 132 | payload["max_id"] = max_id 133 | return self.request("instagram/user/get_media_by_username", payload) 134 | 135 | def get_user_clips(self, user_id, count=12, max_id=None): 136 | """ 137 | Retrieve user clips (videos from "Reels" section) by id. 138 | 139 | Args: 140 | user_id (int): User id 141 | count (int): Number of media to retrieve (max: 12) 142 | max_id (str): Use for pagination 143 | 144 | You can use the `max_id` parameter to paginate through the media (take from the `max_id` (!) field of the response). 145 | 146 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_clips 147 | """ 148 | payload = {"id": user_id, "count": count} 149 | if max_id is not None: 150 | payload["max_id"] = max_id 151 | return self.request("instagram/user/get_clips", payload) 152 | 153 | def get_user_guides(self, user_id, max_id=None): 154 | """ 155 | Retrieve user guides by id. 156 | 157 | Args: 158 | user_id (int): User id 159 | max_id (str): Use for pagination 160 | 161 | You can use the `max_id` parameter to paginate through the media (take from the `next_max_id` field of the response). 162 | 163 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_guides 164 | """ 165 | payload = {"id": user_id} 166 | if max_id is not None: 167 | payload["max_id"] = max_id 168 | return self.request("instagram/user/get_guides", payload) 169 | 170 | def get_user_tags(self, user_id, count=12, max_id=None): 171 | """ 172 | Retrieve user tags by id. 173 | 174 | Args: 175 | user_id (int): User id 176 | count (int): Number of media to retrieve (max: 50) 177 | max_id (str): Use for pagination 178 | 179 | You can use the `max_id` parameter to paginate through the media (take from the `end_cursor` (!) field of the response). 180 | 181 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_tags 182 | """ 183 | payload = {"id": user_id, "count": count} 184 | if max_id is not None: 185 | payload["max_id"] = max_id 186 | return self.request("instagram/user/get_tags", payload) 187 | 188 | def get_user_following(self, user_id, count=12, max_id=None): 189 | """ 190 | Retrieve user following by user id. 191 | 192 | Args: 193 | user_id (int): User id 194 | count (int): Number of users to return (max: 200) 195 | max_id (str): Use for pagination 196 | 197 | You can use the `max_id` parameter to paginate through following (take from the `next_max_id` field of the response). 198 | 199 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_following 200 | """ 201 | payload = {"id": user_id, "count": count} 202 | if max_id is not None: 203 | payload["max_id"] = max_id 204 | return self.request("instagram/user/get_following", payload) 205 | 206 | def search_user_following(self, user_id, query): 207 | """ 208 | Search user following by user id. 209 | 210 | Args: 211 | user_id (int): User id 212 | query (str): Search query 213 | 214 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_following 215 | """ 216 | return self.request( 217 | "instagram/user/get_following", {"id": user_id, "query": query} 218 | ) 219 | 220 | def get_user_followers(self, user_id, count=12, max_id=None): 221 | """ 222 | Retrieve user followers by user id. 223 | 224 | Args: 225 | user_id (int): User id 226 | count (int): Number of users to return (max: 50) 227 | max_id (str): Use for pagination 228 | 229 | You can use the `max_id` parameter to paginate through followers (take from the `next_max_id` field of the response). 230 | 231 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_followers 232 | """ 233 | payload = {"id": user_id, "count": count} 234 | if max_id is not None: 235 | payload["max_id"] = max_id 236 | return self.request("instagram/user/get_followers", payload) 237 | 238 | def search_user_followers(self, user_id, query): 239 | """ 240 | Search user followers by user id. 241 | 242 | Args: 243 | user_id (int): User id 244 | query (str): Search query 245 | 246 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_followers 247 | """ 248 | return self.request( 249 | "instagram/user/get_followers", {"id": user_id, "query": query} 250 | ) 251 | 252 | def get_user_stories_bulk(self, user_ids): 253 | """ 254 | Retrieve user(s) stories by user id(s). 255 | You can retrieve up to 4 user ids per request. 256 | 257 | Args: 258 | user_ids (list): List of user ids 259 | 260 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_stories 261 | """ 262 | return self.request("instagram/user/get_stories", {"ids": user_ids}) 263 | 264 | def get_user_stories(self, user_id): 265 | """ 266 | Retrieve user stories by user id. 267 | 268 | Args: 269 | user_id (int): User id 270 | 271 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_stories 272 | """ 273 | return self.get_user_stories_bulk([user_id]) 274 | 275 | def get_user_highlights(self, user_id): 276 | """ 277 | Retrieve user highlights by user id. 278 | 279 | Args: 280 | user_id (int): User id 281 | 282 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_highlights 283 | """ 284 | return self.request("instagram/user/get_highlights", {"id": user_id}) 285 | 286 | def get_user_live(self, user_id): 287 | """ 288 | Retrieve user live broadcast by id. 289 | 290 | Args: 291 | user_id (int): User id 292 | 293 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_live 294 | """ 295 | return self.request("instagram/user/get_live", {"id": user_id}) 296 | 297 | def get_user_similar_accounts(self, user_id): 298 | """ 299 | Lookup for user similar accounts by id. Typically, up to 80 accounts will be returned. 300 | 301 | Args: 302 | user_id (int): User id 303 | 304 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_similar_accounts 305 | """ 306 | return self.request("instagram/user/get_similar_accounts", {"id": user_id}) 307 | 308 | def get_media_info(self, media_id): 309 | """ 310 | Retrieve media information by media id. 311 | 312 | Args: 313 | media_id (int): Media id 314 | 315 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_info 316 | """ 317 | return self.request("instagram/media/get_info", {"id": media_id}) 318 | 319 | def get_media_info_by_shortcode(self, shortcode): 320 | """ 321 | Retrieve media information by media shortcode. This method provides the same information as the `get_media_info`. 322 | 323 | Args: 324 | shortcode (str): Media shortcode 325 | 326 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_info_by_shortcode 327 | """ 328 | return self.request( 329 | "instagram/media/get_info_by_shortcode", {"shortcode": shortcode} 330 | ) 331 | 332 | def get_media_likes_by_shortcode(self, shortcode): 333 | """ 334 | Retrieve up to 1000 media likes by media shortcode. 335 | 336 | Args: 337 | shortcode (str): Media shortcode 338 | 339 | Pagination is not supported for this endpoint. 340 | 341 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_likes 342 | """ 343 | payload = {"shortcode": shortcode} 344 | return self.request("instagram/media/get_likes", payload) 345 | 346 | def get_media_likes(self, shortcode, count=12, max_id=None): 347 | """ 348 | Retrieve up to 1000 media likes by media shortcode. 349 | This is an alias for get_media_likes_by_shortcode. 350 | 351 | Note: The parameters count and max_id are kept for backward compatibility but are no longer supported. 352 | 353 | Args: 354 | shortcode (str): Media shortcode 355 | count (int): DEPRECATED - No longer supported 356 | max_id (str): DEPRECATED - No longer supported 357 | 358 | Pagination is not supported for this endpoint. 359 | 360 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_likes 361 | """ 362 | # Ignoring count and max_id parameters as they're no longer supported 363 | return self.get_media_likes_by_shortcode(shortcode) 364 | 365 | def get_media_likes_by_id(self, media_id): 366 | """ 367 | Retrieve up to 1000 media likes by media id. 368 | 369 | Args: 370 | media_id (int): Media id 371 | 372 | Pagination is not supported for this endpoint. 373 | 374 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_likes_by_id 375 | """ 376 | return self.request("instagram/media/get_likes_by_id", {"id": media_id}) 377 | 378 | def get_media_comments(self, media_id, can_support_threading=True, min_id=None): 379 | """ 380 | Retrieve media comments by media id. 381 | 382 | Args: 383 | media_id (int): Media id 384 | can_support_threading (bool): Set `False` if you want chronological order 385 | min_id (str): Use for pagination 386 | 387 | You can use the `min_id` parameter to paginate through comments (take from the `next_min_id` field of the response). 388 | 389 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_comments 390 | """ 391 | payload = {"id": media_id, "can_support_threading": can_support_threading} 392 | if min_id is not None: 393 | payload["min_id"] = min_id 394 | return self.request("instagram/media/get_comments", payload) 395 | 396 | def get_media_shortcode_by_id(self, media_id): 397 | """ 398 | Get media shortcode by media id. This endpoint is provided free of charge. 399 | 400 | Args: 401 | media_id (int): Media id 402 | 403 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_shortcode_by_id 404 | """ 405 | return self.request("instagram/media/get_shortcode_by_id", {"id": media_id}) 406 | 407 | def get_media_id_by_shortcode(self, shortcode): 408 | """ 409 | Get media id by media shortcode. This endpoint is provided free of charge. 410 | 411 | Args: 412 | shortcode (str): Media shortcode 413 | 414 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_id_by_shortcode 415 | """ 416 | return self.request( 417 | "instagram/media/get_id_by_shortcode", {"shortcode": shortcode} 418 | ) 419 | 420 | def get_media_id_by_share(self, share): 421 | """ 422 | Get media id by share code (for links like https://www.instagram.com/share/XXXxx356, where XXXxx356 is the share code). 423 | 424 | Args: 425 | share (str): Share code 426 | 427 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/get_id_by_share 428 | """ 429 | return self.request("instagram/media/get_id_by_share", {"share": share}) 430 | 431 | def get_guide_info(self, guide_id): 432 | """ 433 | Retrieve guide information by guide id. 434 | 435 | Args: 436 | guide_id (int): Guide id 437 | 438 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/guide/get_info 439 | """ 440 | return self.request("instagram/guide/get_info", {"id": guide_id}) 441 | 442 | def get_location_info(self, location_id): 443 | """ 444 | Retrieve location information by location id. 445 | 446 | Args: 447 | location_id (int): Location id 448 | 449 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/location/get_info 450 | """ 451 | return self.request("instagram/location/get_info", {"id": location_id}) 452 | 453 | def get_location_media(self, location_id, page=None, max_id=None, tab=None): 454 | """ 455 | Retrieve location media by location id. 456 | 457 | Args: 458 | location_id (int): Location id 459 | page (int): Page number 460 | max_id (str): Use for pagination 461 | tab (str): Tab name: recent, ranked (default: recent) 462 | 463 | 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. 464 | 465 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/location/get_media 466 | """ 467 | payload = {"id": location_id} 468 | if page is not None: 469 | payload["page"] = page 470 | if max_id is not None: 471 | payload["max_id"] = max_id 472 | if tab is not None: 473 | payload["tab"] = tab 474 | return self.request("instagram/location/get_media", payload) 475 | 476 | def get_hashtag_info(self, name): 477 | """ 478 | Retrieve hashtag information by hashtag name. 479 | 480 | Args: 481 | name (str): Hashtag name 482 | 483 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/hashtag/get_info 484 | """ 485 | return self.request("instagram/hashtag/get_info", {"name": name}) 486 | 487 | def get_hashtag_media(self, name, page=None, max_id=None, tab=None): 488 | """ 489 | Retrieve hashtag media by hashtag name. 490 | 491 | Args: 492 | name (str): Hashtag name 493 | page (int): Page number 494 | max_id (str): Use for pagination 495 | tab (str): Tab name: recent, top, or clips (default: recent) 496 | 497 | 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. 498 | 499 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/hashtag/get_media 500 | """ 501 | payload = {"name": name} 502 | if page is not None: 503 | payload["page"] = page 504 | if max_id is not None: 505 | payload["max_id"] = max_id 506 | if tab is not None: 507 | payload["tab"] = tab 508 | return self.request("instagram/hashtag/get_media", payload) 509 | 510 | def get_highlight_stories_bulk(self, highlight_ids): 511 | """ 512 | Retrieve highlight(s) stories by highlight id(s). 513 | 514 | Args: 515 | highlight_ids (list): Highlight id(s) 516 | 517 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/highlight/get_stories 518 | """ 519 | return self.request("instagram/highlight/get_stories", {"ids": highlight_ids}) 520 | 521 | def get_highlight_stories(self, highlight_id): 522 | """ 523 | Retrieve highlight stories by highlight id. 524 | 525 | Args: 526 | highlight_id (int): Highlight id 527 | 528 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/highlight/get_stories 529 | """ 530 | return self.get_highlight_stories_bulk([highlight_id]) 531 | 532 | def get_comment_likes(self, comment_id, max_id=None): 533 | """ 534 | Retrieve comment likes by comment id. 535 | 536 | Args: 537 | comment_id (int): Comment id 538 | max_id (str): Use for pagination 539 | 540 | You can use the `max_id` parameter to paginate through likes (take from the `next_max_id` field of the response). 541 | 542 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/comment/get_likes 543 | """ 544 | payload = {"id": comment_id} 545 | if max_id is not None: 546 | payload["max_id"] = max_id 547 | return self.request("instagram/comment/get_likes", payload) 548 | 549 | def get_comment_replies(self, comment_id, media_id, max_id=None): 550 | """ 551 | Retrieve comment replies by comment id and media id. 552 | 553 | Args: 554 | comment_id (int): Comment id 555 | media_id (int): Media id 556 | max_id (str): Use for pagination 557 | 558 | You can use the `max_id` parameter to paginate through replies (take from the `next_max_child_cursor` field of the response). 559 | 560 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/comment/get_replies 561 | """ 562 | payload = {"id": comment_id, "media_id": media_id} 563 | if max_id is not None: 564 | payload["max_id"] = max_id 565 | return self.request("instagram/comment/get_replies", payload) 566 | 567 | def get_audio_media(self, audio_id, max_id=None): 568 | """ 569 | Retrieve audio media by audio id. 570 | 571 | Args: 572 | audio_id (int): Audio id 573 | max_id (str): Use for pagination 574 | 575 | You can use the `max_id` parameter to paginate through media (take from the `next_max_id` field of the response). 576 | 577 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/audio/get_media 578 | """ 579 | payload = {"id": audio_id} 580 | if max_id is not None: 581 | payload["max_id"] = max_id 582 | return self.request("instagram/audio/get_media", payload) 583 | 584 | def get_audio_media_by_canonical_id(self, audio_canonical_id, max_id=None): 585 | """ 586 | Retrieve audio media by audio canonical id. 587 | 588 | Args: 589 | audio_canonical_id (int): Audio canonical id 590 | max_id (str): Use for pagination 591 | 592 | You can use the `max_id` parameter to paginate through media (take from the `next_max_id` field of the response). 593 | 594 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/audio/get_media_by_canonical_id 595 | """ 596 | payload = {"id": audio_canonical_id} 597 | if max_id is not None: 598 | payload["max_id"] = max_id 599 | return self.request("instagram/audio/get_media_by_canonical_id", payload) 600 | 601 | def get_live_info(self, broadcast_id): 602 | """ 603 | Retrieve live information by broadcast id. 604 | 605 | Args: 606 | broadcast_id (int): Broadcast id 607 | 608 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/live/get_info 609 | """ 610 | return self.request("instagram/live/get_info", {"id": broadcast_id}) 611 | 612 | def get_user_about(self, user_id): 613 | """ 614 | Obtain user details from «About this Account» section. 615 | 616 | Args: 617 | user_id (int): User id 618 | 619 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/get_about 620 | """ 621 | return self.request("instagram/user/get_about", {"id": user_id}) 622 | 623 | def search_users(self, query): 624 | """ 625 | Search for a specific user (max 50 results) 626 | 627 | Args: 628 | query (str): The search query 629 | 630 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/user/search 631 | """ 632 | return self.request("instagram/user/search", {"query": query}) 633 | 634 | def search_hashtags(self, query): 635 | """ 636 | Search for a specific hashtag (max 20 results) 637 | 638 | Args: 639 | query (str): The search query 640 | 641 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/hashtag/search 642 | """ 643 | return self.request("instagram/hashtag/search", {"query": query}) 644 | 645 | def search_locations(self, query): 646 | """ 647 | Search for a specific location (max 20 results) 648 | 649 | Args: 650 | query (str): The search query 651 | 652 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/location/search 653 | """ 654 | return self.request("instagram/location/search", {"query": query}) 655 | 656 | def search_audios(self, query): 657 | """ 658 | Search for a specific audio (max 10 results) 659 | 660 | Args: 661 | query (str): The search query 662 | 663 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/audio/search 664 | """ 665 | return self.request("instagram/audio/search", {"query": query}) 666 | 667 | def search_clips(self, query, max_id=None): 668 | """ 669 | Search for a specific clip with a caption that includes the query (max 12 results) 670 | 671 | Args: 672 | query (str): The search query 673 | max_id (str): Use for pagination 674 | 675 | You can use the max_id parameter to paginate through following (take from the reels_max_id field of the response). 676 | 677 | For more information, see documentation: https://docs.rocketapi.io/api/instagram/media/search_clips 678 | """ 679 | payload = {"query": query} 680 | if max_id is not None: 681 | payload["max_id"] = max_id 682 | return self.request("instagram/media/search_clips", payload) 683 | -------------------------------------------------------------------------------- /rocketapi/rocketapi.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | 4 | class RocketAPI: 5 | def __init__(self, token, max_timeout=30): 6 | """ 7 | RocketAPI client. 8 | 9 | If your base_url is different from the default, you can reassign it after initialization. 10 | 11 | For more information, see documentation: https://docs.rocketapi.io/api/ 12 | """ 13 | self.base_url = "https://v1.rocketapi.io/" 14 | self.version = "1.0.12" 15 | self.token = token 16 | self.max_timeout = max_timeout 17 | 18 | def request(self, method, data): 19 | return requests.post( 20 | url=self.base_url + method, 21 | json=data, 22 | headers={ 23 | "Authorization": f"Token {self.token}", 24 | "User-Agent": f"RocketAPI Python SDK/{self.version}", 25 | }, 26 | timeout=self.max_timeout, 27 | ).json() 28 | -------------------------------------------------------------------------------- /rocketapi/threadsapi.py: -------------------------------------------------------------------------------- 1 | from rocketapi.exceptions import NotFoundException, BadResponseException 2 | from rocketapi.rocketapi import RocketAPI 3 | 4 | 5 | class ThreadsAPI(RocketAPI): 6 | def __init__(self, token, max_timeout=30): 7 | """ 8 | Threads API client. 9 | 10 | Args: 11 | token (str): Your RocketAPI token (https://rocketapi.io/dashboard/) 12 | max_timeout (int): Maximum timeout for requests. Please, don't use values lower than 15 seconds, it may cause problems with API. 13 | 14 | For debugging purposes you can use the following variables: 15 | last_response (dict): contains the last response from the API. 16 | counter (int): contains the number of requests made in the current session. 17 | 18 | For more information, see documentation: https://docs.rocketapi.io/api/ 19 | """ 20 | self.last_response = None 21 | self.counter = 0 22 | super().__init__(token, max_timeout=max_timeout) 23 | 24 | def request(self, method, data): 25 | response = super().request(method, data) 26 | self.last_response = response 27 | self.counter += 1 28 | if response["status"] == "done": 29 | if ( 30 | response["response"]["status_code"] == 200 31 | and response["response"]["content_type"] == "application/json" 32 | ): 33 | return response["response"]["body"] 34 | elif response["response"]["status_code"] == 404: 35 | raise NotFoundException("Instagram resource not found") 36 | else: 37 | raise BadResponseException("Bad response from Threads") 38 | raise BadResponseException("Bad response from RocketAPI") 39 | 40 | def search_users(self, query): 41 | """ 42 | Search for a specific user in Threads 43 | 44 | Args: 45 | query (str): Username to search for 46 | 47 | For more information, see documentation: https://docs.rocketapi.io/api/threads/search_users 48 | """ 49 | return self.request("threads/search_users", {"query": query}) 50 | 51 | def get_user_info(self, user_id): 52 | """ 53 | Retrieve Threads user information by id. 54 | 55 | Args: 56 | user_id (int): User id 57 | 58 | For more information, see documentation: https://docs.rocketapi.io/api/threads/user/get_info 59 | """ 60 | return self.request("threads/user/get_info", {"id": user_id}) 61 | 62 | def get_user_feed(self, user_id, max_id=None): 63 | """ 64 | Retrieve Threads user feed by id. 65 | 66 | Args: 67 | user_id (int): User id 68 | max_id (str): Use for pagination 69 | 70 | You can use the `max_id` parameter to paginate through the media (take from the `next_max_id` field of the response). 71 | 72 | For more information, see documentation: https://docs.rocketapi.io/api/threads/user/get_feed 73 | """ 74 | payload = {"id": user_id} 75 | if max_id is not None: 76 | payload["max_id"] = max_id 77 | return self.request("threads/user/get_feed", payload) 78 | 79 | def get_user_replies(self, user_id, max_id=None): 80 | """ 81 | Retrieve Threads user replies by id. 82 | 83 | Args: 84 | user_id (int): User id 85 | max_id (str): Use for pagination 86 | 87 | You can use the `max_id` parameter to paginate through the media (take from the `next_max_id` field of the response). 88 | 89 | For more information, see documentation: https://docs.rocketapi.io/api/threads/user/get_replies 90 | """ 91 | payload = {"id": user_id} 92 | if max_id is not None: 93 | payload["max_id"] = max_id 94 | return self.request("threads/user/get_replies", payload) 95 | 96 | def get_user_followers(self, user_id, max_id=None): 97 | """ 98 | Retrieve Threads user followers by id. 99 | 100 | Args: 101 | user_id (int): User id 102 | max_id (str): Use for pagination 103 | 104 | You can use the `max_id` parameter to paginate through followers (take from the `next_max_id` field of the response). 105 | 106 | For more information, see documentation: https://docs.rocketapi.io/api/threads/user/get_followers 107 | """ 108 | payload = {"id": user_id} 109 | if max_id is not None: 110 | payload["max_id"] = max_id 111 | return self.request("threads/user/get_followers", payload) 112 | 113 | def search_user_followers(self, user_id, query): 114 | """ 115 | Search Threads user followers by user id. 116 | 117 | Args: 118 | user_id (int): User id 119 | query (str): Search query 120 | 121 | For more information, see documentation: https://docs.rocketapi.io/api/threads/user/get_followers 122 | """ 123 | return self.request( 124 | "threads/user/get_followers", {"id": user_id, "query": query} 125 | ) 126 | 127 | def get_user_following(self, user_id, max_id=None): 128 | """ 129 | Retrieve Threads user following by id. 130 | 131 | Args: 132 | user_id (int): User id 133 | max_id (str): Use for pagination 134 | 135 | You can use the `max_id` parameter to paginate through followers (take from the `next_max_id` field of the response). 136 | 137 | For more information, see documentation: https://docs.rocketapi.io/api/threads/user/get_following 138 | """ 139 | payload = {"id": user_id} 140 | if max_id is not None: 141 | payload["max_id"] = max_id 142 | return self.request("threads/user/get_following", payload) 143 | 144 | def search_user_following(self, user_id, query): 145 | """ 146 | Search Threads user following by user id. 147 | 148 | Args: 149 | user_id (int): User id 150 | query (str): Search query 151 | 152 | For more information, see documentation: https://docs.rocketapi.io/api/threads/user/get_following 153 | """ 154 | return self.request( 155 | "threads/user/get_following", {"id": user_id, "query": query} 156 | ) 157 | 158 | def get_thread_replies(self, thread_id, max_id=None): 159 | """ 160 | Retrieve thread replies by id. 161 | 162 | Args: 163 | thread_id (int): Thread id 164 | max_id (str): Use for pagination 165 | 166 | You can use the `max_id` parameter to paginate through the media (take from the `paging_tokens["downwards"]` field of the response). 167 | 168 | For more information, see documentation: https://docs.rocketapi.io/api/threads/thread/get_replies 169 | """ 170 | payload = {"id": thread_id} 171 | if max_id is not None: 172 | payload["max_id"] = max_id 173 | return self.request("threads/thread/get_replies", payload) 174 | 175 | def get_thread_likes(self, thread_id): 176 | """ 177 | Retrieve thread likes by id. 178 | 179 | Args: 180 | thread_id (int): Thread id 181 | 182 | For more information, see documentation: https://docs.rocketapi.io/api/threads/thread/get_likes 183 | """ 184 | payload = {"id": thread_id} 185 | return self.request("threads/thread/get_likes", payload) 186 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | 4 | setuptools.setup( 5 | name="rocketapi", 6 | version="1.0.12", 7 | author="RocketAPI", 8 | author_email="developer@rocketapi.io", 9 | description="RocketAPI Python SDK", 10 | packages=["rocketapi"], 11 | url="https://github.com/rocketapi-io/rocketapi-python", 12 | download_url="https://github.com/rocketapi-io/rocketapi-python/archive/refs/tags/v1.0.12.tar.gz", 13 | install_requires=["requests"], 14 | ) 15 | --------------------------------------------------------------------------------