You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 1, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+89-46Lines changed: 89 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,15 +19,17 @@ Inspired by [NPM Threads-API](https://github.com/junhoyeo/threads-api)
19
19
20
20
Threads API is an unofficial Python client for Meta's Threads API. It allows you to interact with the API to login, read and publish posts, view who liked a post, retrieve user profile information, follow/unfollow and much more.
21
21
22
-
It allows you to configure the session object. Choose between:
23
-
*`aiohttp` - Python library to ease asynchronous execution of the API, for ⚡ super-fast ⚡ results. (*default*)
24
-
*`requests` - Python library for standard ease of use (supports `HTTP_PROXY` env var functionality)
25
-
*`instagrapi` - utilize the same connection all the way for private api
26
-
* (Advanced) Implement your own and call ThreadsAPI like this: `ThreadsAPI(http_session_class=YourOwnHTTPSessionImpl)`
✅ Authentication Methods supported via `instagrapi`
25
+
26
+
✅ Stores token and settings locally, to reduce login-attempts (*uses the same token for all authenticated requests for up to 24 hrs*)
27
+
28
+
✅ Pydantic structures for API responses (for IDE auto-completion) (at [types.py](https://github.com/Danie1/threads-api/blob/main/threads_api/src/types.py))
29
+
30
+
✅ Actively Maintained since Threads.net Release (responsive in Github Issues, try it out!)
27
31
28
-
> **Note** Since v1.1.10 you can use `requests` or `instagrapi` as HTTP clients, not just `aiohttp`.
29
32
30
-
> **Note** Since v1.1.12 a `.session.json` file will be created by-default to save default settings (to reduce risk of being flagged). You can disable it by passing `ThreadsAPI(settings_path=None)`
31
33
32
34
> **Important Tip** Use the same `cached_token_path` for connections, to reduce the number of actual login attempts. When needed, threads-api will reconnect and update the file in `cached_token_path`.
Upon unexpected error, or upon receiving an exception with: `Oops, this is an error that hasn't yet been properly handled.\nPlease open an issue on Github at https://github.com/Danie1/threads-api.`
149
158
150
-
# Step 3 (Windows): Activate virtual environment
151
-
.\env\Scripts\activate # Windows
152
-
153
-
# Step 4: Install dependencies
154
-
pip install -r requirements.txt
155
-
```
159
+
Please open a Github Issue with all of the information you can provide, which includes the last Request and Response (Set `LOG_LEVEL=DEBUG`)
156
160
157
161
# Supported Features
162
+
-[x] ✅ Pydantic typing API responses at [types.py](https://github.com/Danie1/threads-api/blob/main/threads_api/src/types.py)
158
163
-[x] ✅ Login functionality, including 2FA 🔒
159
164
-[x] ✅ Cache login token securely (reduce login requests / due to restrictive limits)
160
165
-[x] ✅ Saves settings locally, such as device information and timezone to use along your sessions
View [examples/public_api_examples.py](https://github.com/Danie1/threads-api/blob/main/examples/public_api_examples.py) for Public API code examples. For the Private API usage (requires login), head over to [examples/private_api_examples.py](https://github.com/Danie1/threads-api/blob/main/examples/private_api_examples.py)
204
-
205
-
At the end of the file you will be able to uncomment and run the individual examples with ease.
208
+
View [examples/public_api_examples.py](https://github.com/Danie1/threads-api/blob/main/examples/public_api_examples.py) for Public API code examples.
206
209
207
-
Then simply run as:
208
-
```
210
+
Run as:
211
+
```bash
209
212
python3 examples/public_api_examples.py
213
+
```
210
214
211
-
# or
215
+
View [examples/private_api_examples.py](https://github.com/Danie1/threads-api/blob/main/examples/private_api_examples.py) for Private API code examples. (🔒 Requires Authentication 🔒)
result=awaitapi.post("Hello World with an image!", image_path=".github/logo.jpg")
58
55
59
-
ifresult:
60
-
print("Post has been successfully posted")
56
+
ifresult.media.pk:
57
+
print(f"Post has been successfully posted with id: [{result.media.pk}]")
61
58
else:
62
59
print("Unable to post.")
63
60
64
61
# Asynchronously posts a message with an image
65
62
asyncdefpost_include_image_from_url(api):
66
63
result=awaitapi.post("Hello World with an image!", image_path="https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png")
67
64
68
-
ifresult:
69
-
print("Post has been successfully posted")
65
+
ifresult.media.pk:
66
+
print(f"Post has been successfully posted with id: [{result.media.pk}]")
print(f"{thread['containing_thread']['thread_items'][0]['post']['user']['username']}'s post {thread['containing_thread']['thread_items'][0]['post']['caption']}:")
0 commit comments