As the name implies, my goal is to send a tweet from script.gs . Twitter will be sent to my channel, ideally, without me, to visit the Twitter site.
I wrote two main functions:
script.gs
//post tweet function oAuth() { var CONSUMER_KEY = "**********************"; var CONSUMER_SECRET = "*************************************************"; ScriptProperties.setProperty("TWITTER_CONSUMER_KEY", CONSUMER_KEY); ScriptProperties.setProperty("TWITTER_CONSUMER_SECRET", CONSUMER_SECRET); var oauthConfig = UrlFetchApp.addOAuthService("twitter"); oauthConfig.setAccessTokenUrl("https://api.twitter.com/oauth/access_token"); oauthConfig.setRequestTokenUrl("https://api.twitter.com/oauth/request_token"); oauthConfig.setAuthorizationUrl("https://api.twitter.com/oauth/authorize"); oauthConfig.setConsumerKey(ScriptProperties.getProperty("TWITTER_CONSUMER_KEY")); oauthConfig.setConsumerSecret(ScriptProperties.getProperty("TWITTER_CONSUMER_SECRET")); var options = {muteHttpExceptions: true,oAuthServiceName:'twitter',oAuthUseToken:'always'} var url = "https://api.twitter.com/1.1/statuses/user_timeline.json"; var response = UrlFetchApp.fetch(url, options).getContentText(); Logger.log(response); } function postTweet() { oAuth(); Logger.log('oAuth complete'); var status = "Tweet"; var Roptions = { method: "post", oAuthServiceName: "twitter", oAuthUseToken: "always", status: status }; var url = "https://api.twitter.com/1.1/statuses/update.json"; Logger.log('begin post'); var request = UrlFetchApp.fetch(url, Roptions); //the trouble line. Execution stops. Logger.log('post complete'); }
After about a day of inexorable hacking, I was able to get the first oAuth() function to work. These are the logs, well, my user data. However, for the life of me, I cannot understand what the request holds. I get this error: Request failed for returned code 403. Truncated server response: {"errors":[{"message":"SSL is required","code":92}]} . At Google, this is not much affected. I guess the problem is somewhere in Roptions . Any help would be appreciated and I can try to provide further clarification if necessary.
source share