谷歌脚本Twitter机器人搜索短语:地理编码返回零

时间:2015-10-25 09:16:19

标签: javascript twitter geocode

我一直在试验这个Twitter机器人。除了我不能通过Geocode搜索推文之外,它工作得很好。我也通过"附近:伦敦,英国和#34;但我总是得到回报"没有匹配的推文这个回合"。如果我只使用#innovation,它工作正常。

我还检查了Twitter API文档,但没有提示此功能可能已被阻止。 (是的,我在我的版本中插入了API密码等)

感谢任何帮助;)

最大 P.S:为了完整起见,这个项目是基于Labnol的Tutorial



    TWITTER_CONSUMER_KEY    = "";
    TWITTER_CONSUMER_SECRET = "";
    TWITTER_ACCESS_TOKEN    = "";
    TWITTER_ACCESS_SECRET   = "";
    TWITTER_SEARCH_PHRASE   = '#geocode:51.5072,0.1275,100km';

    CHECK_EVERY_MINUTES = 1;
    MIN_DELAY_IN_SECONDS_BETWEEN_ACTION = 10;
    MAX_DELAY_IN_SECONDS_BETWEEN_ACTION = 60;



    // DO NOT CHANGE ANYTHING BELOW THIS LINE

    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"
      });
      
      if (typeof Twitter === "undefined") {
        throw new Error("Please add the Twitter library.");
      }
        
      var twit = new Twitter.OAuth(props);
      
      // Test the favorite/retweet/fetch Twitter operations
      /*
      if (!twit.retweet("628173817559453696")) {
        if (!twit.favorite("628173817559453696")) {
          try {
            twit.fetchTweets("labnol RT to win", null, {count:1});
            Logger.log("Twitter authorization is successful.");
          } catch (f) {
            throw new Error("Please check your Twitter access tokens");
            return;
          }
        }
      }
      */
      
      // Delete exiting triggers, if any
      
      Stop_Bot();
      
      // Setup trigger to read Tweets every five minutes
      
      ScriptApp.newTrigger("labnol_twitterBot")
      .timeBased()
      .everyMinutes( CHECK_EVERY_MINUTES )
      .create();
      
    }

    function Stop_Bot() {
      
      var triggers = ScriptApp.getProjectTriggers();
      
      for (var i = 0; i < triggers.length; i++) {
        ScriptApp.deleteTrigger(triggers[i]);
      }
      
    }

    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) {
              if (!tweet.possibly_sensitive) {
                return tweet.id_str;
              }
            }, {
              multi: true,
              lang: "en",
              count: 5,
              since_id: props.getProperty("SINCE_TWITTER_ID")
            });
          
          if (tweets.length) {
            
            props.setProperty("SINCE_TWITTER_ID", tweets[0]);
            
            for (var i = tweets.length - 1; i >= 0; i--) {
              
              //twit.retweet(tweets[i]);
              try {
                Logger.log("Trying to favorite tweet");
                twit.favorite(tweets[i]);
                Logger.log("Successfully marked tweet as favourite.");
              } catch (f) {
                Logger.log("Did not succeed to mark tweet as favourite.");
              }

              
              /* Wait between MIN_DELAY_IN_SECONDS_BETWEEN_ACTION SECONDS and MAX_DELAY_IN_SECONDS_BETWEEN_ACTION SECONDS */
              Utilities.sleep(Math.floor(Math.random()* ( (MAX_DELAY_IN_SECONDS_BETWEEN_ACTION-MIN_DELAY_IN_SECONDS_BETWEEN_ACTION) * 1000 ) ) + (MIN_DELAY_IN_SECONDS_BETWEEN_ACTION * 1000 ));
              
            }
          }
        }
        
      } catch (f) {
        Logger.log("Error: " + f.toString());
      }
      
    }
&#13;
&#13;
&#13;

0 个答案:

没有答案