Send Personalized Tweets & DMs in Bulk from a Google Spreadsheet
Send Personalized Tweets & DMs in Bulk from a Google Spreadsheet
Whether you're managing a social media campaign, running outreach for your startup, or thanking supporters individually, the ability to send personalized tweets and direct messages (DMs) in bulk can save you hours.
Google Sheets is an excellent platform for managing message templates, contact lists, and personal data. When paired with the Twitter API and Google Apps Script, it becomes a powerful tool to automate Twitter outreach at scale—in a personal and efficient way.
This guide walks you through how to use a Google Spreadsheet to automatically send custom tweets and DMs to multiple users.
? What You'll Learn
-
How to set up a Google Sheet for personalized messages
-
How to connect Google Sheets to the Twitter API
-
How to write a Google Apps Script to send tweets or DMs in bulk
-
How to avoid spammy behavior and stay within Twitter’s rules
?️ Prerequisites
-
A Twitter Developer Account
-
A Twitter API key, API secret, and access tokens
-
A Google Account with access to Google Sheets
-
Basic familiarity with scripting (not mandatory but helpful)
Step 1: Set Up Your Google Sheet
Create a spreadsheet with columns like:
| Twitter Handle | Name | Tweet Message | DM Message | Status |
|---|---|---|---|---|
| @elonmusk | Elon | Hi Elon, love your work on Tesla! ?⚡️ | Thanks for following, Elon! ? | |
| @sundarpichai | Sundar | Hey Sundar, amazing job leading Google! ? | Appreciate your leadership at Google. ? |
You can use formulas to personalize messages. For example, in column C (Tweet Message):
="Hi "&B2&", love your work on Tesla!"
Step 2: Apply for Twitter Developer Access and Generate API Keys
-
Create an app under your developer account.
-
Note your:
-
API Key
-
API Secret Key
-
Access Token
-
Access Token Secret
-
These will allow you to authenticate and interact with the Twitter API.
Step 3: Open Google Apps Script
-
In your Google Sheet, click on Extensions > Apps Script
-
Paste the following base code:
const TWITTER_API_KEY = 'YOUR_API_KEY';
const TWITTER_API_SECRET = 'YOUR_API_SECRET';
const ACCESS_TOKEN = 'YOUR_ACCESS_TOKEN';
const ACCESS_SECRET = 'YOUR_ACCESS_SECRET';
function sendTweetsAndDMs() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = sheet.getDataRange().getValues();
for (let i = 1; i < data.length; i++) {
let username = data[i][0].replace('@', '').trim();
let tweetMsg = data[i][2];
let dmMsg = data[i][3];
try {
if (tweetMsg) {
sendTweet(tweetMsg);
}
if (dmMsg) {
sendDM(username, dmMsg);
}
sheet.getRange(i + 1, 5).setValue("Sent");
} catch (err) {
Logger.log(err);
sheet.getRange(i + 1, 5).setValue("Error: " + err.message);
}
}
}
Now you’ll need the actual functions to send a tweet or send a DM.
Step 4: Add Twitter OAuth Authentication and API Calls
Unfortunately, Google Apps Script doesn't support OAuth 1.0a natively (which Twitter uses). But you can use the OAuth1 library:
-
In Apps Script, click Libraries > Add a Library
-
Use this Script ID for OAuth1:
1B3n1C2WZbTV7v3ZRfPCxYj4-oLqLU1m_19NzN2bNMHqf0e3jJp-Ut-oG -
Now update your script with:
function getOAuthService() {
return OAuth1.createService('Twitter')
.setAccessTokenUrl('https://api.twitter.com/oauth/access_token')
.setRequestTokenUrl('https://api.twitter.com/oauth/request_token')
.setAuthorizationUrl('https://api.twitter.com/oauth/authorize')
.setConsumerKey(TWITTER_API_KEY)
.setConsumerSecret(TWITTER_API_SECRET)
.setAccessToken(ACCESS_TOKEN, ACCESS_SECRET);
}
function sendTweet(tweetText) {
const service = getOAuthService();
const url = "https://api.twitter.com/1.1/statuses/update.json";
const payload = { status: tweetText };
const response = service.fetch(url, {
method: 'post',
payload: payload
});
const result = JSON.parse(response.getContentText());
Logger.log("Tweet sent: " + result.text);
}
function sendDM(username, message) {
const service = getOAuthService();
// Step 1: Get user ID
const userUrl = `https://api.twitter.com/2/users/by/username/${username}`;
const userResponse = service.fetch(userUrl);
const userId = JSON.parse(userResponse.getContentText()).data.id;
// Step 2: Send DM
const dmUrl = 'https://api.twitter.com/1.1/direct_messages/events/new.json';
const event = {
event: {
type: "message_create",
message_create: {
target: { recipient_id: userId },
message_data: { text: message }
}
}
};
const dmResponse = service.fetch(dmUrl, {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(event)
});
Logger.log("DM sent to @" + username);
}
Step 5: Run the Script
-
Save the script.
-
Run the function
sendTweetsAndDMs(). -
Authorize the app when prompted.
-
Tweets and DMs will be sent row by row.
You can also set up a custom menu in the spreadsheet to trigger the function easily.
Step 6: Monitor and Avoid Rate Limits
Twitter has rate limits:
-
Tweets: 300 per 3 hours per user
-
DMs: 1000 per day
-
Use
Utilities.sleep(500)in your loop to pause between messages (0.5 seconds)
Best Practices
-
Personalize every message using sheet formulas (like
"Hi "&A2&", thanks for following!") -
Keep messages short to avoid truncation
-
Don’t spam or send unsolicited DMs—it violates Twitter’s rules
-
Track status using a column like “Sent,” “Pending,” or “Failed”
Conclusion
Sending bulk personalized tweets and DMs from a Google Sheet gives you an edge in managing outreach at scale—without losing the personal touch. Whether you’re thanking followers, announcing product updates, or engaging influencers, automating this process can save time and increase engagement.
With Twitter’s API and Google Sheets, you can turn your spreadsheet into a powerful social media automation dashboard—completely custom and fully under your control.