Skip to content

Instantly share code, notes, and snippets.

@PeterBerthelsen
Created January 20, 2019 16:43
Show Gist options
  • Save PeterBerthelsen/94c340945f788a39681bc0ebd65be259 to your computer and use it in GitHub Desktop.
Save PeterBerthelsen/94c340945f788a39681bc0ebd65be259 to your computer and use it in GitHub Desktop.
OrthoBot Authorization
function sendTweet(TweetText, IdInResponseTo, ImageAttachURL){
//////////////////////////Set Variables///////////////////////////////////////////////////////
var ss = SpreadsheetApp.getActiveSpreadsheet(); //spreadsheet
var logsheet = ss.getSheetByName("TweetLog");
var lastRow = Math.max(logsheet.getLastRow(),1) + 1;
var twitterKeys= { //Twitter Authentication Tokens to pass through props
TWITTER_CONSUMER_KEY: "[YOUR KEY HERE]",
TWITTER_CONSUMER_SECRET: "[YOUR SECRET HERE]",
TWITTER_ACCESS_TOKEN: "[YOUR TOKEN HERE]",
TWITTER_ACCESS_SECRET: "[YOUR SECRET HERE]"
}
var props = PropertiesService.getScriptProperties(); //New Properties Service
props.setProperties(twitterKeys); //Pass Authentication through Service
var params = new Array(0); //Array for params (reply, images, etc)
var service = new Twitter.OAuth(props); //Attempt Connection with Service
console.log("sendTweet Initiated!"); //log function start
console.log("using params:" //log params passed through function
+ "|TweetText: " + TweetText
+ "|IdInResponseTo: " + IdInResponseTo
+ "|ImageAttachURL: " + ImageAttachURL);
//////////////////////////Authenticate////////////////////////////////////////////////////////
if (!service.hasAccess()) { //If credentials do NOT grant access...
console.log("Authorization Failed"); //log authentication failure
} else { //If credentials grant access...
console.log("Authentication Successful"); //log authentication success
var status = TweetText; //Tweet text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment