HOW TO MAKE A TWITTER BOT WITH GOOGLE SPREADSHEETS


SUBMITTED BY: amsaid

DATE: Aug. 8, 2016, 3:39 p.m.

UPDATED: Aug. 8, 2016, 3:41 p.m.

FORMAT: Text only

SIZE: 6.6 kB

HITS: 829

  1. Step 1: Create a Twitter account for your Bot
  2. --------------------------------------------
  3. Go to Twitter.com and sign up for a new account. You can always change the name later, but to make the next steps go smoother, go ahead and confirm the account with an email address and do some of the basic profile setup. For the email address, I like to use the “+something” trick whereby adding “+something” after your name in a Gmail address (as in, “zach.whalen+something@gmail.com”) will force Twitter to see that as a distinct email address, but you will still get that email in your inbox.
  4. You’ll need to verify your email address and a mobile phone number. This is a pain, but it’s what Twitter requires now. If you already have a mobile number associated with a different Twitter account, you’ll have to disconnect that one first. You can always re-arrange those associations later, but the bot account does need to have a mobile number while you’re setting it up.
  5. Enter your account name in your Spreadsheet under Step 1.
  6. Step 2: Create a Twitter App for your Bot
  7. ---------------------------------------
  8. This application (“app”) is the method that your spreadsheet will use to talk to Twitter. It’s possible to use Apps for multiple bots or accounts — in fact, this is how they’re designed — but I like to make one for each bot account so that if one gets suspended the others aren’t necessarily in jeopardy at the same time.
  9. Go to apps.twitter.com and hit the “Create New App” button there. Fill out the form to give your app a name, description, and website. These can be quite simple and can always be changed later. The app’s name needs to be unique, so you can name it the same it based on your bot.
  10. Leave the “Callback” field blank for now. If you get an Error message saying that you must first add a mobile phone number to your profile, then you should do that now.
  11. Step 3: Complete App Setup and Enter Keys into the Spreadsheet
  12. ---------------------------------------------------------------
  13. You App has four tabs: Details, Settings, Keys and Access Tokens, and Permissions. Under Details, make sure that the app’s access level is set to “Read and Write”, and if not, change that under the Permissions tab.
  14. Under the Keys and Access Tokens tab, use the button to “Create my access token.” This will authorize your app to interface with your account. (I know, it seems redundant.)
  15. Then, copy and paste the Consumer Key (API Key) and Consumer Secret (API Secret) from that tab into the green cells under Step 3 in your spreadsheet. (Note: The Consumer Key and Secret are not the same thing as the Access Token and Access Secret.)
  16. Step 4: Locate your Google Spreadsheet’s “Project Key”
  17. -----------------------------------------------------
  18. This is your spreadsheet’s unique ID within Google. To find yours, first open “Tools -> Script Editor…” to bring up the Script Editor. In the Script Editor, open “File -> Project Properties”, and locate your “Project key” in the table that you’ll see there.
  19. Copy and paste that Project key into the green cell under Step 4.
  20. Step 5: Add “Callback” Value to Twitter App
  21. -------------------------------------------
  22. After completing Step 4, the red cell under Step 5 should automatically change to include your Project key as part of a URL. If not, or if you accidentally delete it, the URL follows a simple formula:
  23. https://script.google.com/macros/d/<YOUR PROJECT KEY>/usercallback
  24. Go back to your Twitter app’s Settings tab and paste that URL into “Callback URL” field.
  25. Step 6: Select a Data Sheet and Generate a Preview of its Output
  26. ---------------------------------------------------------------
  27. Select a data sheet from the drop down under Step 6, and from the “Bot” menu in your Spreadsheet, select “Generate Preview”. (Each of the four options has specific setup instructions below, but they’re all pre-populated with sample content for this setup step.)
  28. Switch to the “Preview Output” sheet to see 15 sample tweets generated from the selected data sheet. You can edit these data sheets to your own content now, or you can wait until the rest of the setup is complete.
  29. Generating this preview will require you to authorize the scripts in this spreadsheet, so you should agree to grant it permission if prompted.
  30. Step 7: Test Twitter Authorization
  31. -----------------------------------
  32. You’re almost done! From the “Bot” menu above, select “Send a Test Tweet”. If everything has been set up correctly, you should see a popup inviting you to authenticate your app with your Twitter account. It’s pretty easy. Follow the link, click authorize, then close the new tab when it says. “Success!”
  33. Re-run Send a Test Tweet, and check your timeline. Hopefully it worked!
  34. Step 8: Set Post Timing
  35. ------------------------
  36. Decide how often you want your bot posting, and select an option from the dropdown under Step 8. Unfortunately, these are the only options, and the actually timing is to some extent subject to Google’s whims. You won’t, for example, be able to specify your bot to post at exactly 10:34 every day.
  37. Step 9: Start it up!
  38. --------------------
  39. If everything has gone well so far and your data sheet is populated with your content, then you’re ready to start sending out tweets. Select “Start Posting Tweets” from the Bot menu in your spreadsheet. If ever you decide to stop your bot, then use the “Stop Posting Tweets” option under the Bot menu.
  40. You can change the data sheet selection and edit the data sheet contents without stopping the tweeting. It will simply use the updated setting whenever it next attempts to send a tweet. You will, however, have to stop and restart the posting if you want to change the timing.
  41. “Select from Rows” and “Select from Columns” Setup
  42. These two data sheets are the same, just oriented differently. Each is populated with a nursery rhyme to give you a sense of how it’s going to build the tweet. If you’re upgrading your bot from my SSBot version 0.3, you’ll want to use “Select from Rows” to paste in your vocabulary from the earlier sheet.
  43. If you want to make a bot that posts randomly from pre-composed messages, use the “Select from Columns” and paste all of your messages into a single column.
  44. You’re welcome to add notes or labels to the surrounding rows or columns. For both of these sheets, the script just expects the first potential value (or top-left value) to be in cell B5, so just make sure your tweetable text starts there.

comments powered by Disqus