Thats a simples script to import yours tweets from any Twitter account to a Mastodon account, in any instance.
For this tutorial, you'll need to install Node.js and Git.
- Node.js: Download | Node.js (nodejs.org)
- Git: Git - Downloads (git-scm.com)
Go here for request your Twitter data. You'll recive a link to download a zip file. There will be tweets, images, information etc. It'll be in this configuration:
- twitter
- assets (folder)
- data (folder)
- Your archive (html file)
Extract the file in your Desktop folder. Will be more easy for manipulate. Find the tweets.js file. It'll be, probably inside "data" folder and move it to Desktop.
Clone this repo in your Desktop folder with the command:
git clone https://github.com/FGRibreau/import-tweets-to-mastodon.git
Or download the zip and extract in Desktop.
To request an API key from Mastodon, click here if you are on mastodon.social, otherwise go to https://{your-mastodon.instance}/settings/applications
. Create an new application in "New Application". Set an Application Name (e. g.: api-mastodon-twitter) and, at the end of page, click in "Submit".
- Copy your "Your access token" from developer's page in Mastodon;
- Press "WIN + R" and write "cmd". Click ENTER;
- Go to your Desktop folder;
- Write
MASTODON_API_BASEPATH=https://[YOUR-MASTODON-INSTANCE]
MASTODON_API_KEY=YOUR_ACCESS_TOKEN_FROM_MASTODON
TWITTER_TWEETJS_FILEPATH=tweets.js
- Same thing as Windows;
- Open Terminal;
- Got to your Desktop folder;
- Write
export MASTODON_API_BASEPATH=https://[YOUR-MASTODON-INSTANCE]
export MASTODON_API_KEY=YOUR_ACCESS_TOKEN_FROM_MASTODON
export TWITTER_TWEETJS_FILEPATH=../tweets.js
In the terminal (or CMD), enter in "import-tweets-mastodon" folder, located in Desktop. Write
npm install
After this
node import.js
Command | Default | Explanation |
---|---|---|
TWITTER_TWEETJS_FILEPATH | Path to tweet.js file, e.g. ../twitter-data/data/tweets.js |
|
MASTODON_API_KEY | The API key, looks like y8LptTshBDs4LmL3WTZxINgl4gHFPB0-mOzspqeIinM |
|
MASTODON_API_BASEPATH | The url of your Mastodon instance, e.g. https://mastodon.social | |
TWITTER_LIMITTWEETSTOSETYEAR | true | If only Tweets from the specified year should be considered |
TWITTER_YEAR | current year | |
TWITTER_EXCLUDEREPLIES | true | Whether replies should be posted |
TWITTER_EXCLUDERETWEETS | false | Whether retweets should be posted |
MASTODON_POSTMEDIA | false | Whether media (images and video) should be posted |
TWITTER_MEDIAPATH | Path to media folder, e.g. ../twitter-data/data/tweets_media/ |
|
MASTODON_TIMEOUTBETWEENPOSTS | 0 | Time in seconds between posts, necessary due to rate limit (= less than 1 post/minute when media-heavy). Combine with MASTODON_TIMEOUTBETWEENMEDIAUPLOADS for the right amount. |
MASTODON_TIMEOUTBETWEENMEDIAUPLOADS | 10 | Time in seconds between media uploads, necessary because especially videos need some time processing |
MASTODON_ADDDATEFROMTWEET | false | |
MASTODON_DATETEXT | Originally on Twitter ({date}): \n\n |
If a date should be added, which text should be added ({date} will be replaced by the date) |
MASTODON_CHANGEDATELOCALETO | (if not specified uses your computer's locale) | The set locale (DE = Germany) which affects the date format, e.g. "14/9/2017" in France or "14.9.2017" in Germany |
MASTODON_RUNWITHOUTPOSTING | false | (For testing) You can use to check if all files and data was correct |
TWITTER_LIMITNUMBEROFTWEETS | -1 (= no limit) | Only post the last (=newest) x number of Tweets |
export MASTODON_API_BASEPATH=https://mastodon.social MASTODON_API_KEY=y8LptTshBDs4LmL3WTZxINgl4gHFPB0-mOzspqeIinM TWITTER_TWEETJS_FILEPATH=../twitter-data/data/tweets.js TWITTER_EXCLUDERETWEETS=true, MASTODON_ADDDATEFROMTWEET=true MASTODON_CHANGEDATELOCALETO=DE TWITTER_LIMITTWEETSTOSETYEAR=false MASTODON_POSTMEDIA=true TWITTER_MEDIAPATH=../twitter-data/data/tweets_media/ MASTODON_TIMEOUTBETWEENPOSTS=10 MASTODON_TIMEOUTBETWEENMEDIAUPLOADS=40 MASTODON_PRESERVETHREADS=true
- This project is open-sourced. Feel free to contribute;
- If you really want support please consider sponsoring me 👍