Tweet using Google Script

I pulled this code from this question .

Applying the author’s solution, I always get this error: enter image description here

I get my key and secret from my created Twitter application:

enter image description here

I have an app configured for recording ...

What am I doing wrong?

//post tweet function oAuth() { var CONSUMER_KEY = "xxxx"; var CONSUMER_SECRET = "xxxxx"; 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/authenticate"); 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='Operational!'; var options = { "method": "post", "oAuthServiceName": "twitter", "oAuthUseToken": "always", "payload":{"status":status} }; var url = "https://api.twitter.com/1.1/statuses/update.json"; Logger.log('begin post'); var request = UrlFetchApp.fetch(url, options); Logger.log('post complete'); } 
+5
source share
1 answer

I also got this error until I realized that you need to provide the CallBack URL on Twitter:

Twitter CallBack URL

Defines this as ' https://script.google.com ' or ' https://script.google.com/macros ' allows me to authorize. I tested this and currently I can send a message with the code that you provided .

However, if you try to publish the same text “status” twice, this will cause the following error:

Duplicate status error

This is not a problem, since you just change the value of the Status variable, but it threw me the first time.

+3
source

Source: https://habr.com/ru/post/1203167/


All Articles