- PHP 100%
|
|
||
|---|---|---|
| lib | Update README & Config | |
| .gitignore | Update README & Config | |
| config.sample.php | Make adding title and body optional. Longer char limit | |
| post | Code tidy up | |
| README.md | Tidy up config | |
| rss2threads.php | Correct comments | |
RSS2Threads
- Post items from multiple RSS / Atom Feeds to Threads.
- Post a single status update to Threads.
- No need to set up a database.
Requirements
- PHP with SQLite3, cURL, SimpleXML, and Multibyte String support
- SimplePie
- Threads Account
- Threads Developer Account
On Ubuntu and similar Linux distros, you can install the local requirements with:
apt install php-sqlite3 php-curl php-xml php-mbstring libphp-simplepie
Threads Access
Your Threads Token can be generated at https://developers.facebook.com/apps/ TODO! More info here.
Your User ID is not your @ name. It is an account number.
Get your Threads User ID by running:
curl -s -X GET "https://graph.threads.net/v1.0/me?ields=id,username,name,threads_profile_picture_url,threads_biography&access_token=TOKEN"
See https://developers.facebook.com/docs/threads/threads-profiles/ for documentation.
Installation
Clone this repository.
Configuration
- Rename
config.sample.phptoconfig.php - Edit config.php:
// First feed
$config['feeds'][] = [
'feed-url' => 'https://your.websi.te/feed.rss', // URl of an RSS feed
'feed-item-maxage' => 60*60*24*2, // Maximum age in seconds of feed items that should be posted to Threads
'feed-cache-duration' => 60*60, // Time in seconds after which SimplePie reloads the feed
'threads-user-id' => '1234567', // Numeric User ID
'threads-token' => 'abcd-efgh-ijkl-mnop', // Token
'post-prefix' => 'New! ', // Fixed text prepended before every posted item
'post-suffix' => ' #hashtag', // Fixed text appended after every posted item
];
// Second feed
$config['feeds'][] = [ // repeat $config['feeds'][] for every feed you want to post to Threads
// You may use different accounts, cache-durations etc.
// All configuration options are needed for every feed (no default settings)
];
// Global settings
$config['cache-dir'] = '/path/to/cache'; // absolute path to a directory where SimplePie stores its cache
$config['sqlite-filename'] = $config['cache-dir'].'/rss2threads.db'; // absolute path to the filename for a sqlite3 database, where rss2threads stores status information about feed items
Note
In some configurations a relative path to $config['cache-dir'] works, but I found it best to provide an absolute path, just to be sure.
Run
rss2threads
post all new items of the configured rss feeds to Threads:
/usr/bin/php rss2threads.php
This can be run periodically via cron:
0 * * * * /usr/bin/php /path/to/rss2threads/rss2threads.php > /dev/null
Once per hour is sufficient in most cases. If you need faster updates remember to change feed-cache-duration accordingly.
post
To post a single status:
./post "text of your post in quotes"
License
This repository is CC-BY-4.0 (Creative Commons Attribution 4.0 International).
SimplePie Library New BSD license
See the original RSS2BlueSky code by Thomas Nesges.
With thanks to Jesse Chen for their Python Threads example code.