I created a tweeter bot for retraction and sympathy for tweets using the Agarwal tutorial , which uses the Twitter lib library to search for tweets. I am using Twitterlib version 21 in my project.
This seems to work for the most part, but I have one specific problem. When I include the parameter "min_retweets: X" in my search, it does not seem to be recognized. This is not an officially registered search parameter, but it works when you use it on a regular twitter site and returns only tweets that have been rewritten X times.
If I make "min_retweets: X" the first search term, the search will not return any results. If I make this the last search term, I get results, but they are not limited to tweets that have been rewritten X times.
I searched a bit in the fetchtweets () method inside Twitterlib, but at the moment I don't understand where this problem could be here. Version 21 of the library says that it was updated to make the search with ":" correct, and this seems accurate as far as some other search terms I used, not this one. There's also a min_faves: X parameter, but I have not tested it if it works with Twitterlib search.
If anyone knows of a workaround to get this working, I would appreciate it. Below is the code that I use to call the function and the code for the function itself from the Twitter library:
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")
});
OAuth.prototype.fetchTweets = function(search, tweet_processor, options) {
var tweets, response, result = [], data, i, candidate;
var phrase = encodeString('lang:' + (options && options.lang || 'en') + ' ' + encodeString(search).replace(/%3A/g, ":"));
this.checkAccess();
if(options == null) {
options = {};
}
var url = [
"https://api.twitter.com/1.1/search/tweets.json?count=",
(options.count || "5"),
options.filter ? ("&filter=" + encodeString(options.filter)) : "",
"&include_entities=",
options.include_entities ? encodeString(options.include_entities) : "false",
"&result_type=",
options.result_type ? encodeString(options.result_type) : "recent",
"&q=",
phrase,
options.since_id ? "&since_id=" + encodeString(options.since_id) : ""
].join("");
var request_options =
{
"method": "get"
};
try {
response = this.fetch(url, request_options);
if (response.getResponseCode() === 200) {
data = JSON.parse(response.getContentText());
if (data) {
tweets = data.statuses;
if(!tweet_processor) {
return options && options.multi ? tweets : tweets[tweets.length - 1];
}
for (i=tweets.length-1; i>=0; i--) {
candidate = tweet_processor(tweets[i]);
if(candidate === true) candidate = tweets[i];
if(candidate) {
if(options && options.multi) {
result.push(candidate);
} else {
return candidate;
}
}
}
if(result.length) {
return result;
}
if(i < 0) {
Logger.log("No matching tweets this go-round");
}
}
} else {
Logger.log(response);
}
} catch (e) {
Logger.log(JSON.stringify(e));
throw e;
}
return result;
}