Yes, really.
The reason is pretty simple.
Google Sheets are super easy to use, and while there are a few “bots” out there for Sheets, most of them are simple copy-and-paste your credentials and it’ll do some very limited, pre-defined action.
What I’ve created here is the base functionality for you to interact with Twitter’s API.
This version so far has functions to send tweets and threads (which most premade bot templates do not have), but it’s possible to interact with retweets, favorites, and more.
I’m not interested in making a bot that simply sends a few tweets based on a column in a spreadsheet, I want you to have total control and be able to create something really interesting and dynamic with nothing but a file on a Google Drive.
If you have no programming experience, you can still use this.
If you do, though, you’ll be able to expand upon it with ease.
Below I’ll outline everything you need to do.
If you haven’t already, take a look at the original article:I Made A Twitter Bot From Nothing But A Google SheetAnd I Didn’t Even Know The Scripting Language…medium.
comStep One: Create A Twitter AppFirst, log into the Twitter account to which your bot will connect.
Then go to the Twitter Developer Page.
Under Apps, click on “Create an app”.
If you already have a developer account, you will be directed to the steps below.
If you do not have an account, you’ll need to create one.
This process is a bit of a pain, but it’s fairly self-explanatory.
Simply follow the instructions on each section and submit your application.
Once approved, you can create an application on the Apps Page.
Here, you’ll need to enter a name for your App.
This name will be visible to anyone on Twitter.
When you send a tweet from any source, it will display on your tweet.
Perhaps you’ve seen where a user’s tweet will have a small label “Twitter for Android” or “Twitter Web Client”.
This is the app name that generated the tweet, so name appropriately, the world will see it whenever your bot tweets!There are a few required fields here, so fill them out and enter any additional information like terms of service, etc.
in the appropriate fields.
Lastly, give your app a detailed description and hit Create.
Twitter will give you a stern warning about their policies.
It is actually a good idea to review these prior to applying for a dev account, as some of the use cases you provide may “violate our terms of service”.
Should this happen, they will likely not tell you and you’ll have to send them lots of emails.
I speak from experience.
It took me 2 months to get approval because I didn’t know these things.
Don’t be like me.
Read this, and this, and especially this, then make sure your defined use cases don’t violate any of these policies.
Once your confident of your app, simply hit Create.
Now your app will appear in your Apps list.
Click on it to bring up the App Details.
You can add a thumbnail photo and change details as needed.
What we need, however, is the Keys and tokens tab.
Go ahead and click it.
You will unfortunately not start out with any Access token & access token secret, so click Create to get them.
Now, you will see four App credentials: your API Key, API Secret Key, Access Token, and Access Token Secret.
Take note of these, you’ll need them later.
NOTE: Do not share these credentials as anyone with them can manipulate your app and even tweet as you.
This is definitely not something you want!.Ensure that you don’t make these publicly available, like taking a screenshot of them and posting them on Medium (again, don’t be like me).
In the event these do manage to become public, you can always regenerate them and the old ones will become invalid.
That’s it!.You have an App and your credentials.
Now let’s get a copy of the template.
Step Two: Copy The SheetOnce you have a Twitter Developer account and have created an App, you’ll need to copy the Google Sheets template.
First, click here to open the sheet and click File > Make a copy…Change the name and pick where you want it stored in your Google Drive, then hit OK.
Do NOT Share it with the same people, as the sheet you’re copying is available to literally everyone!Once you have your own copy, you can open it and run a script.
The easiest way to do this is to simply enter some text into the “Tweet Text” box on the SendTweets sheet and hit ‘Send Tweet’ in E5.
Don’t worry, this won’t actually send a tweet as you haven’t entered your Twitter App credentials.
The reason we’re doing this now is to get the pesky security warnings out of the way.
You see, when you copy someone’s files from Google, if they have GAS coded on the back end, you have to give the file explicit permission to run the scripts.
This is similar to Microsoft Excel presenting you with the “Enable Macros” option.
It’s a security measure to make sure you don’t download an otherwise innocuous spreadsheet that has a bunch of scripts running in the background that you don’t know about.
When you run the first script, it will present a popup requiring authorization, hit Continue.
Now, select the Google Account to which you want to save your copy.
Each Google account has its own drive, so if you’re like me, you’ll have a list here with a few to choose from.
If you intend on making a bot with a lot of data pulls from the web and timed script executions, I would highly recommend creating a designated Google Account for your bot, as Google will only offer you so much free processing time (per account, of course).
Once you select your account, Google will issue you the ominous security warning.
But fear not!.Simply hit Advanced and the option Go to googleSheetTwitterBot (unsafe) will appear on the bottom.
Go ahead and click on that bottom link.
Slightly biased language, Google…NOTE: This security warning is actually a good thing.
If Google hasn’t verified an application — which it considers files with GAS — it will make sure that you are well aware of this.
In most circumstances, developers aren’t out to steal your information, and luckily for most Sheets, if you don’t make any edits to the file, you can view the scripts on the back end before doing anything (except onOpen executions) and get rid of the file if anything looks off.
There is naturally an element of trust that goes into getting code from anyone on the web; in most cases, people will just download a program to their computer.
For cloud-based applications in Google Drive, you are simply made aware that there is a security risk.
The term “Only proceed if you know and trust the developer” is important here.
If you’re still with me, that’s great!.I’m glad to know I’m a trusted random internet person!.Let’s move on.
Once you get past the security warning, Google will once again try and dissuade (read: inform) you.
You will be presented with a list of permissions.
This is similar to when you download an app from any app store.
Some apps have additional permissions that you need to approve.
This will seem like a laundry list of potential red flags, but let me put your mind at ease: once you copy this sheet, it becomes yours.
While your copy of googleSheetTwitterBot will be able to view, edit, and manage your content, it is still you who is in control of the file.
There is nothing in these scripts that will send anything back to me personally.
I’m not even skilled enough to code something that would do so.
However, this is another important security notice because some applications may be much more interactive — communicating with a server, for instance — than this one is.
As always, know the risks and proceed only if you “know and trust”.
Once you click your way through the security notifications, you should be good to run any script.
If you took my advice from earlier and hit the “Send Tweet” button, you may see some dialogue appear at the top of the screen, and an inevitable error because you haven’t entered your access credentials.
It’s time to do that now.
Step Three: Enter Your CredentialsWith the spreadsheet open, select Tools > Script editor.
This option is your best friend for making a twitter bot, so get very familiar with it.
Clicking this will open a new tab with the GAS editor.
Do note that this is how you can examine the scripts running in a sheet prior to granting permission to the application in the previous step.
I won’t discuss the inner workings of the code you will see here as I have already done so in detail in my previous article.
We will, however, need to update the credentials, so navigate down to the sendTweet function and locate the twitterKeys object (in the original version, Tweet.
gs, lines 49–54).
Here you will find the four necessary credentials to enter.
Get these from your Twitter App and enter them here.
Make sure you keep these as string values within the double-quotes.
That’s it!.Now you’re ready to tweet.
Go back to the sheet and try hitting the “Send Tweet” button again.
If your credentials are correct, you should see the tweet sent to your Twitter account instantly.
Now it’s time to get creative!Step Four: Start CodingWhile it’s pretty cool to type in tweet text in a cell and have it appear on Twitter, this is still very manual.
Luckily, Google Sheets is a great way to store and manipulate data, so create some new spreadsheets, pull in data from the web with importXML and create some additional scripts that gather data from your spreadsheet, then use the sendTweet or tweetThread functions I’ve created to tweet them out.
The sky is the limit!Once you have some data and the scripts to process it, set up some app timers to automate the process and create a fully-functioning bot.
My bot, OrthoBot captures data from a variety of sources and tweets it out throughout the day.
It’s basically a glorified content curator with some other cool features.
Things to ConsiderCheck out the Twitter library for GAS.
Utilizing this will allow you to engage with Twitter’s API quite easily.
Read up on Google’s Getting Started with GAS page.
This has a lot of great information and is a fine resource for knowing the syntax for the framework.
For quick debugging of code, use logger.
log() instead of console.
log.
Logger will log just the same as Console, but it’s more quickly available in View > Logs within the script editor.
Console is better for longevity, but you have to access an external site to see GAS console logs.
This is available from View > Stackdriver LoggingIf you need help getting started, or have any questions, feel free to respond below.
Let me know what kind of bots you’re looking to make!.