简体   繁体   English

无法获取Twitterlib fetchtweets()以从列表返回查询

[英]Can't get Twitterlib fetchtweets() to return queries from a list

first time here and just started investigating Twitter bots to retweet traffic info to my followers. 第一次来这里,并且刚刚开始调查Twitter机器人,以将路况信息转发给我的关注者。 Am using Amit Agarwal's labnol bot on Google Script and have changed very little (removed favoriting tweets) but I cannot get it to retweet anything using my search parameters despite there being matching tweets on Twitter, could someone check what I'm doing wrong, I don't know enough (yet) to spot the problem? 我正在Google Script上使用Amit Agarwal的labnol机器人,并且变化很小(删除了收藏夹中的推文),但是尽管Twitter上存在匹配的推文,但我无法使用搜索参数来推文任何东西,有人可以检查我在做什么,我还不了解(尚未)发现问题? Thanks in advance. 提前致谢。

// Written by Amit Agarwal @labnol on 31/07/2015

// Fill the Twitter Keys and then choose Run -> Start Bot

TWITTER_CONSUMER_KEY    = "removed";
TWITTER_CONSUMER_SECRET = "removed";
TWITTER_ACCESS_TOKEN    = "removed";
TWITTER_ACCESS_SECRET   = "removed";
TWITTER_SEARCH_PHRASE   = 'A13 list:a13essex/traffic';

function Start_Bot() {

  var props = PropertiesService.getScriptProperties();

  props.setProperties({
    TWITTER_CONSUMER_KEY: TWITTER_CONSUMER_KEY,
    TWITTER_CONSUMER_SECRET: TWITTER_CONSUMER_SECRET,
    TWITTER_ACCESS_TOKEN: TWITTER_ACCESS_TOKEN,
    TWITTER_ACCESS_SECRET: TWITTER_ACCESS_SECRET,
    SINCE_TWITTER_ID: 0
  });

  var twit = new Twitter.OAuth(props);

  // Test Twitter authorization

  if (!twit.favorite("628053456071192576")) {
    throw new Error("Please check your Twitter access tokens");
    return;
  }

  ScriptApp.newTrigger("labnol_twitterBot")
  .timeBased()
  .everyMinutes(10)
  .create();

}

function labnol_twitterBot() {

  try {

    var props = PropertiesService.getScriptProperties(),
        twit = new Twitter.OAuth(props);

    if (twit.hasAccess()) {

      var tweets = twit.fetchTweets(
        TWITTER_SEARCH_PHRASE, function(tweet) {
          // Skip tweets that contain sensitive content
          if (!tweet.possibly_sensitive) {
            return tweet.id_str;
          }
        }, {
          multi: true,
          lang: "en", // Process only English tweets
          count: 5,   // Process 5 tweets in a batch
          since_id: props.getProperty("SINCE_TWITTER_ID")
        });

      if (tweets) {

        props.setProperty("SINCE_TWITTER_ID", tweets[0]);

        for (var i = tweets.length - 1; i >= 0; i--) {

          twit.retweet(tweets[i]);

          /* Wait between 10 seconds and 1 minute */
          Utilities.sleep(Math.floor(Math.random()*50000) + 10000);

        }
      }
    }

  } catch (f) {
    Logger.log("Error: " + f.toString());
  }

}

// Email: amit@labnol.org
// Premium Support: http://ctrlq.org

This returns the following result in the log: 这将在日志中返回以下结果:

[16-09-30 11:25:32:289 BST] https://api.twitter.com/1.1/search/tweets.json?lang=en&count=5&since_id=undefined&include_entities=false&result_type=recent&q=A13%20list%3Aa13essex%252Ftraffic
[16-09-30 11:25:32:292 BST] lang=en
[16-09-30 11:25:32:293 BST] count=5
[16-09-30 11:25:32:293 BST] since_id=undefined
[16-09-30 11:25:32:294 BST] include_entities=false
[16-09-30 11:25:32:294 BST] result_type=recent
[16-09-30 11:25:32:295 BST] q=A13 list:a13essex%2Ftraffic
[16-09-30 11:25:32:375 BST] No matching tweets this go-round

Is https://api.twitter.com/1.1/search/tweets.json?lang=en&count=5&since_id=undefined&include_entities=false&result_type=recent&q=A13%20list%3Aa13essex%252Ftraffic correct? https://api.twitter.com/1.1/search/tweets.json?lang=zh-TW&count=5&since_id=undefined&include_entities=false&result_type=recent&q=A13%20list%3Aa13essex%252Ftraffic是否正确? Thanks again, Paul 再次感谢Paul

You've identified another special character encoding issue with fetchTweets. 您已经发现fetchTweets的另一个特殊字符编码问题。 I did some API checks and the encoding of slash should be %2F on the URL to return the proper result set. 我进行了一些API检查,URL上的斜杠编码应为%2F以返回正确的结果集。

I've filed an issue on Github for the next release: https://github.com/airhadoken/twitter-lib/issues/16 我已经在下一个版本的Github上提交了一个问题: https : //github.com/airhadoken/twitter-lib/issues/16

In the meantime you can use twit.fetch("https://api.twitter.com/1.1/search/tweets.json?lang=en&count=5&since_id=undefined&include_entities=false&result_type=recent&q=A13%20list%3Aa13essex%2Ftraffic") as a workaround; 在此期间,您可以使用twit.fetch("https://api.twitter.com/1.1/search/tweets.json?lang=en&count=5&since_id=undefined&include_entities=false&result_type=recent&q=A13%20list%3Aa13essex%2Ftraffic")作为解决方法; you will have to JSON.parse the content text to get the tweets as objects. 您将必须JSON.parse内容文本才能将tweet作为对象。 I'll report back when you can use fetchTweets() again (ie when Twitter lib v23 is ready to release). 当您可以再次使用fetchTweets()时(即Twitter lib v23准备发布时),我会报告。

Thanks for letting me know! 谢谢你让我知道! -- Bradley Momberger, creator/maintainer of Twitter lib. -Twitter lib的创建者/维护者Bradley Momberger。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM