Note: I didn't write this code. I just found it on Reddit one day. In fact, here’s the original post from u/K0902.
Do you ever see those “Twitter for Samsung Smart Fridge” Tweets? Or maybe “Twitter for Toilet Paper?” Turns out, anyone can do that. For free.
It might seem complicated, but trust me: once you get it set up the first time, it’s super easy to do it again.
Step 1: Create a Twitter Developer account for free at https://developer.twitter.com. It might take a few days for review. Just say you’re working on a program for personal use to post Tweets from. When asked what your primary reason for using Developer tools is, I recommend choosing Exploring the API or Something else.
Step 2: Once you’re in, head here: https://developer.twitter.com/en/apps/create. The App Name is whatever you want to Tweet from. It can’t be one that someone has already claimed, but you can create as many as you want. I think.
Step 2.1: For the description and under “Tell us how this app will be used”, just write “A program for personal use. It will allow me to post Tweets from a specific "device" by manually importing code into a program.”
Step 2.2: Under Website URL, enter your website if you have one. If not, just enter twitter.com. Everything else on this page can be left blank.
Step 3: Make sure Edit app permissions is changed from Read to Read and Write in your App’s dashboard in the developer portal.
Step 4: Enable 3rd party authentication in your App’s dashboard in the developer portal.
Step 5: Download PyCharm here: https://www.jetbrains.com/pycharm/download/. It’s free.
Step 6: Once downloaded, create a new project with whatever name you want.
Step 6.1: Once in PyCharm, go to Terminal and enter pip install tweepy.
Step 7: You’re almost done! Go back to https://developer.twitter.com/en/apps, click on Details next to your app, then click on Keys and Tokens.
Step 7.1: Head to https://pastebin.com/MLr3DZ4Y. Copy and paste the tokens from https://developer.twitter.com/en/apps and paste it where marked. Don’t know where to place it? Open your computer’s Notes app.
Step 7.2: Where it says “ENTER TWEET TEXT HERE,” enter your Tweet text. It’s still limited to Twitter’s 280 character maximum.
Step 6: Go back to PyCharm, then go to Python Console. Copy all of the modified code from PasteBin, paste it, and press enter. Check your account, and it should appear!