TweetifyMusic is a Twitter bot that automatically tweets your recently played song on Spotify on a manually scheduled basis using GitHub Actions. It leverages the Twitter and Spotify APIs to fetch the latest played song from Spotify and post it on your Twitter account.
Automated tweeting: TweetifyMusic connects to your Spotify account and retrieves the most recently played song. It then automatically tweets the song details on your connected Twitter account.
Manual scheduling: You have full control over when the tweets are posted. You can manually schedule the tweets according to your preference using GitHub Actions.
Twitter and Spotify API integration: TweetifyMusic uses the Twitter API to post tweets and the Spotify API to fetch your recently played songs. The integration allows for seamless communication between the two platforms.
To run TweetifyMusic locally, you'll need the following:
spotipy
and tweepy
Clone this repository to your local machine:
git clone https://github.com/AzeemIdrisi/TweetifyMusic.git
Navigate to the project directory:
cd TweetifyMusic
Install the required dependencies:
pip install spotipy tweepy
Set up Spotify API credentials:
http://127.0.0.1:8080/callback
. Make sure to retrieve the Client ID and Client Secret and store them in a secure text file.Edit the get_refresh_token.py file:
python3 get_refresh_token.py
Set up Twitter API credentials:
Edit the tweetifymusic.py OR Export environment variables:
For running TweetifyMusic locally, you have 2 choices. Follow whichever you find easier:
Option 1 - Edit the tweetifymusic.py:
os.environ["KEY_NAME"]
with your API credentials as strings.For example:
Change client_id = os.environ["SPOTIFY_CLIENT_ID"]
to client_id = "123yiuh47fguyer47546562c8476865485644bghf78"
Option 2 - Export API keys as environment variables:
export SPOTIFY_CLIENT_ID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
export SPOTIFY_CLIENT_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXX
export TWITTER_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
export TWITTER_API_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
export TWITTER_BEARER_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXX
export TWITTER_ACCESS_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
export TWITTER_ACCESS_TOKEN_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
export SPOTIFY_REFRESH_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Replace the placeholder values with your actual API credentials.
Run the bot:
python3 tweetifymusic.py
The bot will fetch your recently played song from Spotify and post it on Twitter.
If TweetifyMusic manages to tweet your recently played song on Spotify when run on a local machine, then you can proceed to set up the GitHub Action to automate it.
Schedule the tweets using GitHub Actions:
You can find this in your repository under:
Repository Settings -> Security -> Secrets and Variables -> Actions -> New repository secret.
Now add all your API credentials one by one with the following names:
Name | Secret (without double quotes) |
---|---|
SPOTIFY_CLIENT_ID | Paste your API credential here without quotes |
SPOTIFY_CLIENT_SECRET | Paste your API credential here without quotes |
SPOTIFY_REFRESH_TOKEN | Paste your API credential here without quotes |
TWITTER_ACCESS_TOKEN | Paste your API credential here without quotes |
TWITTER_ACCESS_TOKEN_SECRET | Paste your API credential here without quotes |
TWITTER_API_KEY | Paste your API credential here without quotes |
TWITTER_API_SECRET | Paste your API credential here without quotes |
TWITTER_BEARER_TOKEN | Paste your API credential here without quotes |
Your repository secrets should look like this screenshot -
This will save your API credentials which are only visible to you.
The default workflow will run once every 24 hours. To change it, edit the TweetifyMusic/.github/workflows/main.yml and edit - cron: '0 */24 * * *'
.
Go to the Actions tab of the repository and run the workflow.
Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request.
This project is licensed under the GPL-3.0 License. See the LICENSE file for details.
Mohd Azeem - @AzeemIdrisi