A simple and free way to post RSS feeds to Threads
Threads is Meta's attempt to disrupt the social media landscape. Whether you care for it or not, there are a lot of users there. And, sometimes, you have to go where the audience is.
Here's how I build a really simple PHP tool to post to Threads using their official API. This allows you to send a single status update programatically, or regularly send new items from your RSS feed to an account.
You can see the bot in action at https://www.threads.net/@openbenches_org
Get the code
The code is available as Open Source. It should be fairly self explanatory for a moderately competent programmer - but feel free to open an issue if you think it is confusing.
Get it working
- Create an account on Threads (duh!) - this involves signing up to Instagram.
- Create a Facebook Developer account.
- Create an app which requests the Threads posting API.
- You do not need to publish this app if you're only using it yourself.
- Create a User Token using the "User Token Generator"
- Get your Threads account's User ID with:
curl -s -X GET "https://graph.threads.net/v1.0/me?ields=id,username,name,threads_profile_picture_url,threads_biography&access_token=TOKEN"
- (Yes,
ields
. If you usefields
you get something else!)
- Clone the RSS2Threads repo and stick it on a webserver somewhere.
- Rename
config.sample.php
toconfig.php
and add your feeds' details, along with your ID and Token. - Run
php rss2threads.php
And that's it!
The service will download your RSS feed, check if it has posted the entries to Threads and, if not, post them.
How I built it
Shoulders of giants, and all that! I have been using Thomas Nesges's RSS2BSky for auto-posting to BlueSky. I also used Jesse Chen's Python Threads example code.
Posting is a two stage process.
- POST the URl encoded text to:
https://graph.threads.net/USER_ID/threads?text=My%20post&access_token=TOKEN&media_type=TEXT
- If successful, the API will return a Creation ID.
- POST the Creation ID to:
https://graph.threads.net/USER_ID/threads_publish?creation_id=CREATION_ID&access_token=TOKEN
- If successful, the API will return a Post ID.
Successful RSS posts are stored in a simple SQLite database. If an RSS entry was posted successfully, it won't be reposted.
Caveats
- There are no unit tests, fuzzing, or exception handling. It's assumed you're running this on well-formed RSS that you trust.
- The Threads API is slow! It takes ages for a post to be sent to it.
- Getting a Threads API token is difficult and the margin is too small for me to explain it here.
Feedback
Please leave a comment here or on the code repository.