Google Script/Sheets - Twitter API Integration POST statuses/update in_reply_to_status_id
I am not a developer so I apologize in advance if my question is really basic. I've managed to successfully install this Google script Twitter API integration below and send tweets from a Google sheet (the code was offered here). I simply use =sendTweet(message)
in a cell, replacing message
with the cell reference of where i have the text for the tweet, for example =sendTweet(C6)
and the new Tweet will contain the pre-prepared text in cell C6
.
What i'm trying to do is to add to the script the option of sending a tweet in reply to another tweet. Reading on Twitter's API documentation, I understand that the in_reply_to_status_id
parameter needs to pass the in_reply_to_status_id
in the API call URL but that's as far as my understanding goes.
I don't know how to define this new tweet_id variable and how to get it to pass the in_reply_to_status_id=tweet_id
string in the right place so it will function. The ideal would be to use the same formula but with the addition of tweet_id
for the reply, as a second variable. For example =sendTweet(message, tweet_id)
.
Your help would be much appreciated 🙏
// User-level Twitter API request // Requires the OAuth1 library to be pasted into the script. // https://developers.google.com/google-ads/scripts/docs/examples/oauth10-library var CONSUMER_KEY = '************************'; var CONSUMER_SECRET = '************************'; var ACCESS_TOKEN = '************************'; var ACCESS_SECRET = '************************'; /** * Sends a tweet. * @param {string} message The message to send. * @return {?Object} The complex response object with the status of the send * request. See https://dev.twitter.com/rest/reference/post/statuses/update * for the structure of this object. */ function sendTweet(message) { if (typeof OAuth1 === 'undefined') { var libUrl = 'https://developers.google.com/google-ads/scripts/docs/examples/oauth10-library'; throw Error('OAuth1 library not found. Please take a copy of the OAuth1 ' + 'library from ' + libUrl + ' and append to the bottom of this script.'); } var params = ''; var tweet = message.substring(0, 160); var options = {method: 'POST', payload: {status: tweet}}; var authUrlFetch = OAuth1.withAccessToken(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_SECRET); var response = authUrlFetch.fetch('https://api.twitter.com/1.1/statuses/update.json', params, options); var responseText = response.getContentText(); return JSON.parse(responseText); }