使用Google Script进行鸣叫 [英] Tweet using Google Script

查看:93
本文介绍了使用Google Script进行鸣叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从这个问题中提取了此代码.

I pulled this code from this question.

应用作者的解决方案时,总是会遇到此错误:

Applying the author's solution, I am always given this error:

我从这里创建的Twitter应用程序中获得了密钥和秘密:

I get my key and secret from my created twitter app here:

我已将应用配置为可以写...

I have the app configured to write...

我在做什么错了?

//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');
}

推荐答案

我也遇到了此错误,直到意识到您需要在Twitter中指定回调URL":

I was getting this error also, until I realized you need to specify a 'CallBack URL' in Twitter:

将其指定为" https://script.google.com "或" https://script.google.com/macros '允许我进行授权.我已经对此进行了测试,目前可以使用您列出的代码进行发布.

Specifying that as either 'https://script.google.com' or 'https://script.google.com/macros' is allowing me to Authorize. I've tested this and it's currently letting me post with the code that you've listed.

但是请注意,如果您尝试两次发布相同的状态"文本,则会引发以下错误:

One note however if you try and post the same 'status' text twice, it will throw you the following error:

这不是问题,因为您只需更改变量状态"的值,但这是我第一次想到.

This isn't an issue as you simply change the value of the variable 'Status', but it threw me the first time.

这篇关于使用Google Script进行鸣叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆