How to use the unofficial Threads API (with code samples)
This post is out of date
This post has been migrated from my old blog. It may have broken links, or missing content.
Threads is Facebook’s new social media platform similar to Twitter. In this blog post, I’ll show you how to interact with the private API via a Python package called threads-net
(check it out here).
Note that this API is private, and this package is a reverse engineered implementation of how to access and interact with it. You can lose access to your Threads/Instagram account by using this. You have been warned!
The below instructions all use the command-line.
First, make sure you have Python installed:
Now, install the threads-net package:
We’ll open a Python REPL to interact with the package, though you could create a new .py
file and write a script if you’d prefer:
Authentication can be tricky — you either need to pull an auth token and device information from an actual device, or use the package to generate it.
Note that depending on how you use the API from this interface, your Threads (and Instagram) account could get flagged… so be careful and be reasonable when it comes to the number of requests you’re making.
Let’s have the threads-net
package generate authentication details for us:
If the login is successful, you should be able to retrieve your user id using the get_user_id
function:
You can use that ID to retrieve information about the user as a Python dictionary:
Now, let’s create a new thread using the create_thread
function:
You can see that created post here.
If you’d like to make multiple posts in a single thread, you can specify the reply_to
parameter to indicate that a new post should be threaded to a previous post:
Finally, we can follow accounts using the follow_user
function. In the below example, I’ll follow @7dotdev account — make sure to do the same 🙂