This is Python library to just post to Threads
Project description
Threads Post
A Python module to handle single, carousel, and reply posts on Meta’s Threads using the Graph API.
This module wraps functionality such as creating containers, checking status, publishing posts, and replying to posts in a class-based interface.
Table of Contents
Features
- Single Post: Create a simple text or single-media post.
- Carousel Post: Create a multi-media (up to 10 items) carousel post.
- Replies: Reply to existing posts with either single or carousel posts.
- Status Checks: Automatically checks for processing completion (videos, images).
Installation
-
Clone or Download the repository:
git clone https://github.com/Mr-SuperInsane/ThreadsPostModule.git
or download the ZIP file and extract it.
-
Install the dependencies:
pip install -r requirements.txt
Make sure you have Python 3.7+ installed.
Usage
-
Import the Module:
from threads_post import ThreadsPost
-
Instantiate and Call:
# Create an instance poster = ThreadsPost() # Prepare your post_data post_data = { "accessToken": "<your_access_token>", "userId": "<threads_username>", "mainPost": { "content": "Hello, Threads!", "media": ["<image_or_video_url>"] }, "replyPost": [ { "content": "This is a reply", "media": ["<image_or_video_url>"] } # ... more replies if needed ] } # Post poster.post(post_data)
-
Check Logs:
The module prints out status information (e.g., container IDs, creation times) which you can log or debug.
Example
Here’s a minimal code example that uses ThreadsPost:
from threads_post import ThreadsPost
def main():
# Replace these with your own valid access token, user ID, etc.
post_data = {
"accessToken": "YOUR_LONG_ACCESS_TOKEN",
"userId": "your_threads_username",
"mainPost": {
"content": "My first Threads Post via the API!",
"media": []
},
# Optional: Replies
"replyPost": [
{
"content": "This is a reply to my post",
"media": []
}
]
}
# Create a ThreadsPost instance and make the post
poster = ThreadsPost()
poster.post(post_data)
if __name__ == "__main__":
main()
- Run the above script (
python main.py). - Observe the console output for created container IDs, published post IDs, etc.
API Reference
class ThreadsPost
ThreadsPost()
Constructor; initializes any default configurations.
ThreadsPost.post(post_data)
Main entry point to create a single or carousel Threads post (and optionally create replies).
- Parameters:
post_data: Dictionary with required fields:accessToken(str): Valid Threads Graph API access token.userId(str): Threads username or ID.mainPost(dict): Contains the main post’s content and media list.content(str, optional): Text to post.media(list, optional): URLs of images or videos.
replyPost(list, optional): A list of replies, each a dict ofcontentandmedia.
- Raises:
ValueErrorif the required fields are missing or invalid.Exceptionif the API calls fail or time out.
ThreadsPost.singlePost(access_token, apiUserId, content, media, status, user_id)
Handles single media or text-only post creation.
ThreadsPost.carouselPost(access_token, apiUserId, content, media, status, user_id)
Handles multi-media carousel post creation.
ThreadsPost.replyPost(access_token, apiUserId, replyPostData, id)
Handles posting replies (both single and carousel).
ThreadsPost.get_api_user_id(access_token)
Retrieves the user ID from the provided access token.
ThreadsPost.checkStatus(access_token, container_id, media_type)
Checks the status of media processing up to a specified timeout (3 minutes).
Happy Posting on Threads!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file threadspost-0.0.1.tar.gz.
File metadata
- Download URL: threadspost-0.0.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff297bf0b7e2a3cd3c88b2b526d82e74bdefbebaa241a03626dfbc8782bda39f
|
|
| MD5 |
34988c5b26992c10b31f827f40f7aa81
|
|
| BLAKE2b-256 |
843790a83c42a60751e77c5d04402e03d2a9019a09404d6357fd6b0fa49a9f80
|
File details
Details for the file ThreadsPost-0.0.1-py3-none-any.whl.
File metadata
- Download URL: ThreadsPost-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a11ee682b007a8a281121fa06b76666f8e834f86630d019449413cee88d6bb3
|
|
| MD5 |
7060c8b2529b06ae868e97eb30353b42
|
|
| BLAKE2b-256 |
12c80dfa97aa041046639032e96785a607c79c3985205bb937adae4fada78689
|