Explore ↓
Tweet From a Sheet
About this Tutorial
Sheet Resources
Video Transcript
00:06 Because, yes, I had AI help me write it, but AI was not writing it correctly and kept getting some errors and some failures.
00:15 So I'm gonna walk through a few of the things that I think you'll need in order to be able to tweet from a sheet yourself.
00:21 So, if you're watching this on BetterSheets.com, then down below is this exact sheet and this exact Apps Script that you're going to need in order to tweet from a sheet.
00:33 And here's what we do. We write a tweet in column A, and when we send it, it's going to give us a timestamp of when it's sent.
00:41 It's gonna give us the ID of that tweet, because maybe later we wanna create replies or quote tweets or whatever.
00:47 forever. Thank you. But also, we'll get a URL, and in this video, I'm gonna show you how to edit the script so we get that URL.
00:54 It's actually pretty simple, but you'll need your username. Now, also, the extent of how this works is you select a line that you've written a tweet on, you go up to the X or Twitter, uh, custom menu that I've created here, and you tweet an active row.
01:11 Now, what else? What else can this do? It can also, uh, tweet on schedule. You can schedule your tweets here, but, like, we will need to add more stuff to that, and if you wanna add more automations and triggers, you're gonna want to watch the whole, or, not the whole one, but the lessons in Spreadsheet
01:31 Automation 101. Why that's important is because you'll be able to read this script, Thank you You'll be able to edit it, and you'll be able to create the triggers you need to do, which are just a few clicks away, but I just want to focus on you getting over to Spreadsheet Automation 101 and learning
01:47 that. But here, this is how we set it up. I'm gonna also go through the script, but I'm also gonna go through a few of the things that you need to do on the developer side of X, uh, or Twitter that are a little clunky.
02:02 So what you're gonna end up needing in your script is the API key, the API key secret, access token, and access token secret.
02:08 These last two, a little bit complicated, but I'm gonna show you how to get it really, really, really easily. Here are the notes that I'm gonna go through later, but I want to just walk through this script very quickly because it's not that complicated.
02:21 On open, we're gonna add this menu, and this menu can be anything you want. This, uh, text here, X slash Twitter, could be any text.
02:31 You can say post on X slash Twitter You don't even have to use X. The add item, this tweet active row, is gonna activate the function tweet active row, so that needs to stay the same.
02:43 And that's gonna be right here, function tweet active row. I'm gonna save this right now because I've edited it, and in order to edit it, this on open and actually see it, I'm gonna have to actually close this Apps Script, go over to the sheet, and refresh the sheet.
02:55 So if you ever do those changes, just know you have to actually refresh the sheet and save your change. There it is, post on Twitter.
03:01 So go back to extensions, Apps Script, and here we will keep going, tweet active row. We're just gonna get the active sheet that we're on, get the row, we're gonna get the value in the first column.
03:15 So this comma one is the first column, meaning A. If your column of tweets are in a different column, just change this one to whatever actual column it is.
03:27 And if there is no tweet, it'll say no tweet text found. So like, if we go here, let's say we're on this row, post on Twitter, tweet active row.
03:36 We will have to I'll see authorize it and then it'll tell you it can't do it. Ah, so we will get the ID by posting it.
03:46 So what this is doing is it's going to a custom function called post tweet and we're going to take that text that we have here and we're going to tweet it.
03:55 When we come back at the end of this, we're going to put a timestamp in column two. We're going to put the ID in column three, and I'm going to show you in this video how to add the URL.
04:05 So we're going to add a URL here. Add URL in, in column four. What we're going to need there is a username.
04:16 So we're going to have a global function here, username. This one can't be on Twitter if you want to check me out.
04:25 There we go. So now let's go to this custom function. It's taking this text of this tweet and it's posting it and getting back an ID.
04:35 So here we've written function, postTweet, has some text. It's going to api.twitter.com slash two slash tweets. This is the URL it's going to send to.
04:44 The what it's going to send is the payload, and that's a JSON of, here's the text. The headers, now this is really, this is probably the most complicated part.
04:53 We need to, like, build a OAuth header with all of this stuff up here, and that is a whole nother function.
05:00 So we create the header of authorization saying we're authorized to post for this person, and here's all the options here.
05:07 This is the, the method that we're doing, the content type of our, our action, our payload, and our header authorization.
05:13 All together, send it, now what we get back, we're gonna send it through this URL fetch app, and what we get back is a code that says, is it correct or not, and we get a body, we get some information back, and if we return, we go into that body, and we say, hey, it's JSON, let's parse it, and let's go
05:31 to the data, and let's go to the ID, and find it, and return it. That's all that's doing. So it's all sending that stuff, and then getting back an ID.
05:38 So let's skip down to this build-out header. This one is a little crunchy. It's sort of doing a lot of stuff for us, but it's just taking these API key, access token, it's turning it into a HMACSH1, it's like an encrypted way to send data, it's taking the API keys, putting them in the right format, in
05:57 the right place, getting back signatures, and it's using using, this was, this was sort of the chunky, complicated part, is basically when I wrote this script originally, it was not using the correct, uh, utility, so in Google Sheets and Apps Script, there's only a few of these utilities that are computing
06:17 this signature, And we needed to actually set up that, hey, use SHA-1, and here's the important part. Formation, and here's the signing key, again, signing key is just the secret stuff here, and we're going to get that really, really soon, so you're going to get the API key, you're going to get an access
06:35 token, and all the secrets, and you're going put them in here, now, I want to be very, very clear, this is not, this Apps Script and this Google Sheet is not a safe place to put this stuff, I just want to mention it here.
06:49 if you're sharing your sheet, but if you're not sharing your sheet, if you are keeping your sheet restricted, you're not sharing it with anyone, if you are just writing your own tweets, and you just want to schedule them, and you don't want to pay for a schedule, this is perfect for you, but if you are
07:04 , uh, sending this to, let's say, freelancers, or people in your same company, and you're saying, hey, write the tweets here, and then I'll send them, and then you're just getting this Apps Script to do it, it's not safe.
07:18 It's not safe at all. People can access your Apps Script and see your secrets, and they're going to charge you money, because the Twitter API charges you money.
07:26 So, don't share these information. Now, there are a few ways to share this sheet exactly as it is, and have these tokens somewhere URL.
07:41 You can access this. Again, that's why I would recommend you take the course Spreadsheet Automation 101, because if we use the URL Fetch App to another sheet, we can.
07:49 We can get another sheet here, we can put all this stuff in another sheet, and then access it through that.
07:53 Again, keep that sheet secret, but you're going to run into some problematic situations where you need to run it as yourself, you need to set up sort of automations that run for, as yourself, and then anyone can access it.
08:05 So, I just recommend not doing that. Cool. So, we got our header, we got our tweet out. Now, how do we get this, these pieces of information?
08:16 So, we're going to go on to Twitter. By the way, this is, this is the tweet I wrote. I'm writing this inside of a Google sheet, tweet from a sheet, And I did that just to show you that there was a difference.
08:25 A, actual, ah, tweet from the sheet. But we're going to go to console.x.com. We're going to go to our accounts, and you're going to need to create an app.
08:35 The app has its own keys. That is the API key and API key secret. Then, you're going to go to this page, which is apps.
08:46 You're going to select, you can select any number of apps you have. This, this is the most complicated part. Select your app.
08:53 Over on the right side, you will see OAuth 1.0 keys, and you will also see OAuth 2.0 keys. Ignore 2.0.
08:58 Go to OAuth 1.0, and I've already generated mine, but you will need to click generate, and it'll ask you, like, are you sure you want to regenerate, blah, blah, blah.
09:11 Yes, I want the keys. This is this is your, your, uh, second part of this, the access token and access token secret, okay?
09:21 So these OAuth keys that you create after you create the, a, app, uh, this will be your, those two pieces.
09:29 So you need four pieces of information. Two of those is when you create the app, and the, and the second two pieces are the third and fourth two pieces are here.
09:37 OAuth 1.0. Now, it was super confusing for me. Look at me, I had created the OAuth 2.0 keys and I was like, yeah, that'll work.
09:43 Nope, it doesn't. Okay, over on the left side, make sure you go to billing, uh, and get some credits. So here, I've bought five dollars of credits and I've already gone through two cents because I, uh, posted two times.
09:59 It's like about a cent per, uh, post. There you go. So make sure you have credits, make sure you actually get the OAuth 1.0, uh, keys here, and you'll be good to go.
10:14 You'll be good to go to tweet this. So let's add one more thing to the, uh, outcome of this. And we're going to post, uh, what is it, here, add URL in the fourth column.
10:25 So we're going to go SpreadsheetApp.getActiveSpreadsheet, ActiveSpreadsheet, nope, ActiveSheet, getRange, row, that's just the variable that we have right now, row4.setValue, and now we want a tweet URL.
10:45 So we're going create a variable tweet URL here and that's going to, having to equal, let me get it one second, it's going to be all of this here.
11:00 Put that in, plus the tweet ID. So it's just going to add that tweet ID. Where do you get this name from?
11:09 It's going to be, actually I'm going to use not single quotes, but I'm going I'm gonna use backtick. Because right here, I want to do dollar sign, curly bracket, end curly bracket, and inside it, I'm going to put this username, this variable username.
11:28 So what that does is it's called interpolation and it's just saying, hey, in this string, where there's dollar sign, curly user name, put it in the text that's up there.
11:36 Done. Now. There is another way to do this, and I will show you here, just in case you wanted to know, we don't need to use, uh, these backticks, we could use quotes, single quote, we could end the quote here, add a plus sign, and instead of interpolation, we just use that username, and then again, plus
11:59 sign, quote, status, slash, and then quote. So, you see, these two lines are exactly the same. It's just saying, plus username inside of these two strings, and then we're gonna add the tweet ID at the end.
12:13 That's fine as well, but I like this interpolation, it's pretty cool, but you gotta make sure you use backticks, not single quotes.
12:20 So I'm gonna, x that, uh, not x that out, comment that out, Save it, and there you go. So. That's how you use this sheet.
12:28 Make sure you use your own username here. All of these script and the sheet is down below in the description if you're watching this on BetterSheets.
12:37 If you're not, join!
Courses
Add Icons To Your Sheets With a Domain Name
00:04:21
Tweet From a Sheet
Add Tasks to Google Tasks From Google Sheets
Expense Tracker Template with Data Entry Form Inside Sheets
Convert Google Sheets into a REST API
Build a Book Recommender with AI in Google Sheets
Build a License Key Generator and API in 20 Minutes
Create Your Own API by Deploying a Web App
Access Free API's with Google Sheets
Use Random Quote API in Google Sheets
OpenSea Data Inside Sheets
Tag Emails From A List of Members in Google Sheets
Spreadsheet Automation 101 Lesson 4: Access APIs Introduction
How to Validate Email Addresses
Build Your Own Free Domain Availability Checker
Build a Job Status Checker API in 15 Minutes
Spreadsheet Automation 101 Lesson 4: UrlFetchApp
Spreadsheet Automation 101 Lesson 4: OmdbAPI get ApiKey, get Data in URL
Spreadsheet Automation 101 Lesson 4: OmdbAPI Parameter Picker
Spreadsheet Automation 101 Lesson 4: OmdbAPI get data in Apps Script
Spreadsheet Automation 101 Lesson 4: JSON (beautifier) and OmdbAPI parameters
Quickstart Tutorial OpenAI API in Google Sheets
Shaman: AI Blog Writer
ChatGPT Clone in Google Sheets Part 1
ChatGPT Clone in Google Sheets Part 2
How To Set Up Stripe Webhook to Google Sheets with Google Script
00:22:10
Create Instant QR Codes
Access the Dictionary API to get Definitions for Words in Google Sheets
Sheet Stories / Video Notes + ADDED: Email Notifications
00:00:00
Fast FAQS
Enter Google Drive File Name Get URL
ChatGPT Clone in Google Sheets Part 2
Create an Internal Google Sheets Add-on
Tweet From a Sheet
Why Different Cell References in AI Integration in Sheets?
Show Sheet Tabs Based on Edit
Add Title Case to Google Sheets
How to Power Testimonials with Google Forms and Sheets
Getting Started Coding in Apps Script
Seek Errors When Coding Apps Script
Think Like a Programmer: Develop The Mindset of an Apps Script Coder
ChatGPT Clone in Google Sheets Part 1
Embed a Number in a Website from a Google Sheet
Create Navigation Like A Book or Presentation
Add Click Tracking To Your Google Sheets | Bitly in a Google Sheet
00:29:08
Hold a Giveaway Raffle in a Google Sheet
Embed a Headline in a Website from Google Sheets
Quickstart Tutorial OpenAI API in Google Sheets
Capture Emails from Website Form to a Google Sheet (Without Zapier)
Create a new Spreadsheet from just a Name in a Sheet.
00:05:21
Bjarne Asks: Can I show the Last Time of the Last Edit in a sheet?
00:05:43
Email Yourself a Cell from a Google Sheet, Every Day
OpenSea Data Inside Sheets
Create an Email Campaign Stats Calculator
00:35:13
Twitter App Clone in a Google Sheet
Dylan Asks: How to Automatically Delete Rows If Cell Contains Value
Highlight Row as You Move Your Cell Selection
Create a Timer with Apps Script
LinkTree in a Google Sheet
00:11:22
Password Protecting Data In a Google Sheet
Automatic Weekly Backup of Google Sheets
Create a CPM Custom Function (Create Better Calculators!)
Move Entire Row when a Cell is changed to "Yes" - The $75,000 Google Script
00:12:29
What Can You Automate in Google Sheets? Every single trigger available to Google Sheet users
Sync Two Tabs Without ImportRange()
Google Sheets Stories? No! But we'll add timestamped video notes to your google sheets.
00:00:00
Password Protecting Data In a Google Sheet Part 2 The Basics
Benoit Asks: How to Convert Case
00:07:35
Learn to Code in Google Sheets, For Programmers
Add a Checkbox to Turn on Dark Mode
00:05:10
Write Your First Script
00:08:31
Find Keywords in Any Column. Create quick search dropdown to find keywords
00:09:37
Basic CRM - Add a Powerful Script To Move Row Based on Status
How To Improve: 1,000 Business ideas: Business Idea Generator
00:11:20
Let's Make a Bookmarklet!
00:12:37
Troubleshooting Bitly in a Google Sheet Script
00:07:07
Unique Features - Design a Better Dashboard Part 2
00:04:13
How To Set Up Stripe Webhook to Google Sheets with Google Script
00:22:10
How to Edit a Macro
00:08:22
Sheet Stories / Video Notes + Clear 24 Hour Old Videos
00:35:10
Add A Timestamp to Task Lists (without Now Formula)
00:07:44
Make your Custom Functions Like Native Functions | Custom Function Autocomplete
00:17:58
Create a Changelog Between 2 Cells Custom Function | To learn Double For Loop
00:23:26
New Syntax for WhatChanged Formula in Google Script
00:07:14
How to Record Macros
00:06:20
2 Ways to Delete Lines Quickly (CAREFUL, it's a script!)
00:09:53
Deep Inside Dark Habits Google Script
00:18:54
How to Trigger Macros Daily
00:06:58
5 Ways to Create Coupon Codes | Create UUIDs
Create a Radio Button From Checkboxes Using Google Apps Script
00:15:01