<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>140dev &#187; Search API</title>
	<atom:link href="http://140dev.com/twitter-api-programming-blog/category/search-api/feed/" rel="self" type="application/rss+xml" />
	<link>http://140dev.com</link>
	<description>Twitter API Programming Tips, Tutorials, Source Code Libraries and Consulting</description>
	<lastBuildDate>Wed, 31 Jul 2019 10:03:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.6</generator>
		<item>
		<title>Search API: Are search results filtered for user quality?</title>
		<link>http://140dev.com/twitter-api-programming-blog/search-api-are-search-results-filtered-for-user-quality/</link>
		<comments>http://140dev.com/twitter-api-programming-blog/search-api-are-search-results-filtered-for-user-quality/#comments</comments>
		<pubDate>Fri, 29 Nov 2013 18:08:35 +0000</pubDate>
		<dc:creator>Adam Green</dc:creator>
				<category><![CDATA[Search API]]></category>

		<guid isPermaLink="false">http://140dev.com/?p=2551</guid>
		<description><![CDATA[A continual question on the Twitter developer mailing list is why certain tweets and even entire accounts don&#8217;t show up in search results. The standard answer is that the search API filters out tweets that don&#8217;t meet a minimum quality threshold. That makes a lot of sense, and should definitely be done, if it returns [&#8230;]]]></description>
				<content:encoded><![CDATA[<p></p><p>A continual question on the Twitter developer mailing list is why certain tweets and even entire accounts don&#8217;t show up in search results. The standard answer is that the search API filters out tweets that don&#8217;t meet a minimum quality threshold. That makes a lot of sense, and should definitely be done, if it returns in better results. </p>
<p>I decided to test the Search API using the quality metrics I would typically apply in my own code to filter out spam accounts: account age, number of followers, and number of tweets. I wrote the following <strong>search_quality.php</strong> script, and ran it against 100 different query terms. Each execution of the script collected up to 100 tweets and returned the minimum account values found for these quality criteria. What I found was very surprising. <em>For most queries I was able to get back tweets from accounts that were as little as 1 day old, had zero followers, and had sent only 1 or 2 tweets.</em> </p>
<p>The test script uses the tmhOAuth.php OAuth library, as I do in all my code. If you don&#8217;t already have a copy of this library, you can <a href="http://140dev.com/download/search_quality.zip">download it</a> along with the search_quality.php script. You will need to fill in a set of OAuth tokens to make the API request. You also need to fill in your own query. Try different queries and see what you get.</p>
<p><strong>search_quality.php</strong></p>
<pre>
&lt;?php
// Connect through OAuth
require('tmhOAuth.php');

// You must fill in a set of valid OAuth keys here
$connection = new tmhOAuth(array(
'consumer_key' => '*****',
'consumer_secret' => '*****',
'user_token' => '*****',
'user_secret' => '*****'
));

// Get up to 100 tweets
// You must fill in the query term
$connection-&gt;request('GET', $connection-&gt;url('1.1/search/tweets'),
array('q' =&gt; '*****',
'result_type' =&gt; 'recent',
'count' =&gt; 100));

// Extract tweets
$results = json_decode($connection-&gt;response['response']);
$tweets = $results-&gt;statuses;

if (sizeof($tweets)==0) {
  print "No tweets found for: $query";
  exit;
}

// Loop through all tweets found
$tweets_found = 0;
$min_account_age = account_age($tweets[0]-&gt;user-&gt;created_at);
$min_followers_count = $tweets[0]-&gt;user-&gt;followers_count;
$min_statuses_count = $tweets[0]-&gt;user-&gt;statuses_count;
foreach($tweets as $tweet) {
  ++$tweets_found;

  if ($min_account_age &gt; account_age($tweet-&gt;user-&gt;created_at)){
    $min_account_age = account_age($tweet-&gt;user-&gt;created_at);
  }
  if ($min_followers_count &gt; $tweet-&gt;user-&gt;followers_count) {
    $min_followers_count = $tweet-&gt;user-&gt;followers_count;
  }
  if ($min_statuses_count &gt; $tweet-&gt;user-&gt;statuses_count) {
    $min_statuses_count = $tweet-&gt;user-&gt;statuses_count;
  }
}

print "Tweets found: $tweets_found Minimum account age: $min_account_age " .
"Minimum followers: $min_followers_count Minimum tweets: $min_statuses_count";

// Return number of days since start date
function account_age($start) {
  date_default_timezone_set('America/New_York');
  $end = date('Y-m-d H:i:s',time());
  return round(abs(strtotime($start)-strtotime($end))/86400) + 1;
}

?&gt;</pre>
<p>After you run this, tweet your results to me <a href="http://twitter.com/140dev">@140dev</a>, and I&#8217;ll pass them along to the rest of the 140dev community. </p>
<p>Of course, if you write your own search API code, and collect the results, you can filter out the tweets based on any quality control rules you want. This is one of the ways developers can add value to Twitter API results. </p>
<p id="ttext">Test the search API to see if poor quality users are filtered out.</p>
]]></content:encoded>
			<wfw:commentRss>http://140dev.com/twitter-api-programming-blog/search-api-are-search-results-filtered-for-user-quality/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Search API: More secret search operators</title>
		<link>http://140dev.com/twitter-api-programming-blog/search-api-more-secret-search-operators/</link>
		<comments>http://140dev.com/twitter-api-programming-blog/search-api-more-secret-search-operators/#comments</comments>
		<pubDate>Tue, 26 Nov 2013 14:47:17 +0000</pubDate>
		<dc:creator>Adam Green</dc:creator>
				<category><![CDATA[Search API]]></category>

		<guid isPermaLink="false">http://140dev.com/?p=2540</guid>
		<description><![CDATA[Last week I pointed out the undocumented search operator min_retweets. I&#8217;ve been searching tweets about this operator (yes, that is pretty meta) and found two more operators that aren&#8217;t in the official docs: min_replies and min_faves. You&#8217;ll have to experiment with these to see which are best for different needs. Before we get into the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p></p><p><a href="http://140dev.com/twitter-api-programming-blog/search-programming-secret-query-operator-min_retweets/">Last week</a> I pointed out the undocumented search operator min_retweets. I&#8217;ve been searching tweets about this operator (yes, that is pretty meta) and found two more operators that aren&#8217;t in the official docs: min_replies and min_faves. You&#8217;ll have to experiment with these to see which are best for different needs. Before we get into the details, you should be aware that as undocumented features there is no guarantee they will continue to be available. I guess that is the true for documented features of the API as well. </p>
<p>Personally, I find min_retweets most useful for identifying influential users. Min_replies also implies influence, but an even better use is finding a group of people who know each other well enough to carry on an extended conversation. You can collect all the replies to a tweet and extract the user names. If this is done repeatedly, you can build up a highly engaged circle of friends. Min_faves implies that the tweets are some of the most informative, even if their authors aren&#8217;t that influential. </p>
<p>You can use these operators directly in search.twitter.com:<br />
<a href="https://twitter.com/search?q=obama%20min_retweets%3A5&#038;src=typd&#038;f=realtime">https://twitter.com/search?q=obama%20min_retweets%3A5&#038;src=typd&#038;f=realtime</a><br />
<a href="https://twitter.com/search?q=obama%20min_replies%3A5&#038;src=typd&#038;f=realtime">https://twitter.com/search?q=obama%20min_replies%3A5&#038;src=typd&#038;f=realtime</a><br />
<a href="https://twitter.com/search?q=obama%20min_faves%3A5&#038;src=typd&#038;f=realtime">https://twitter.com/search?q=obama%20min_faves%3A5&#038;src=typd&#038;f=realtime</a></p>
<p>There is a trick when you use them with the search API. You have to include the operators as part of the query parameter, not as a separate parameter. To get tweets with &#8220;obama&#8221; and a minimum of 5 retweets, you set the q parameter to &#8220;obama min_retweets:5&#8243;. Here is an example in the API Console:<br />
<a href="http://140dev.com/twitter-api-console/?method=GET&#038;url=1.1/search/tweets&#038;q=obama%20min_retweets:5&#038;run=1">http://140dev.com/twitter-api-console/?method=GET&#038;url=1.1/search/tweets&#038;q=obama%20min_retweets:5&#038;run=1</a></p>
<p>The complete search API call when using the tmhOAuth.php library is:<br />
$connection->request(&#8216;GET&#8217;,<br />
  $connection->url(&#8217;1.1/search/tweets&#8217;),<br />
    array( &#8216;q&#8217; => &#8216;obama min_retweets:5&#8242;));</p>
]]></content:encoded>
			<wfw:commentRss>http://140dev.com/twitter-api-programming-blog/search-api-more-secret-search-operators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Search API: What are the real limits on tweet results?</title>
		<link>http://140dev.com/twitter-api-programming-blog/search-api-what-are-the-real-limits-on-tweet-results/</link>
		<comments>http://140dev.com/twitter-api-programming-blog/search-api-what-are-the-real-limits-on-tweet-results/#comments</comments>
		<pubDate>Mon, 25 Nov 2013 21:31:44 +0000</pubDate>
		<dc:creator>Adam Green</dc:creator>
				<category><![CDATA[Search API]]></category>

		<guid isPermaLink="false">http://140dev.com/?p=2530</guid>
		<description><![CDATA[A common question asked by potential clients is how many tweets they can expect to get from the search API. Although I have been telling them &#8220;1,500 tweets up to 7 days old&#8221; for years, I decided to confirm that. To my surprise, the limit is no longer provided in the official docs. I tried [&#8230;]]]></description>
				<content:encoded><![CDATA[<p></p><p>A common question asked by potential clients is how many tweets they can expect to get from the search API. Although I have been telling them &#8220;1,500 tweets up to 7 days old&#8221; for years, I decided to confirm that. To my surprise, the limit is no longer provided in the <a href="https://dev.twitter.com/docs/api/1.1/get/search/tweets">official docs</a>. I tried asking for the current limits on the developer mailing list and got no answer, so I&#8217;m going to try an experiment. My hope is that the developer community can come up with our own answers for this important limit.</p>
<p>I wrote a simple test script that counts the tweets and also reports on the date of the oldest tweet returned. Running this myself gave me two possible answers. When I used a low volume query of my town of &#8220;lexington mass&#8221;, I got 24 tweets going back 7 days, which is what I expected. But when I used the high volume query of &#8220;obama&#8221;, I got 17,773 tweets before the script hit the rate limit for requests. Clearly something has changed in a big, yet undocumented way. </p>
<p>Here is the script I used, called <strong>search_limits.php</strong>. It uses the tmhOAuth.php OAuth library, as I do in all my code. If you don&#8217;t already have a copy of this library, you can <a href="http://140dev.com/download/search_limits.zip">download it</a> along with the search_limits.php script. You will need to fill in a set of OAuth tokens to make the API request. You also need to fill in your own query. Try different queries and see what you get.</p>
<p><strong>search_limits.php</strong></p>
<pre>&lt;?php

// Connect through OAuth
require('tmhOAuth.php');
$connection = new tmhOAuth(array(
	'consumer_key'    => '*************',
	'consumer_secret' => '*************',
	'user_token'      => '*************',
	'user_secret'     => '*************'
));
	
// Loop through search results and accumulate count
$query = '*************';
$max_id = 0;
$oldest_tweet = '';
$tweets_found = 0;
while (true) {

  // First API call
  if ($max_id == 0) {
    $connection->request('GET', $connection->url('1.1/search/tweets'), 
      array('q' => $query,
      'result_type' => 'recent',
      'count' => 100));
				
   // Repeated API call
   } else {
    // Collect older tweets
    --$max_id;
		
    $connection->request('GET', $connection->url('1.1/search/tweets'), 
      array('q' => $query,
      'result_type' => 'recent',
      'count' => 100,
      'max_id' => $max_id));
  }			

  // Exit on error
  if ($connection->response['code'] != 200) {
    print "Exited with error: " . $connection->response['code'] . "\n";
    break;			
  } 

  // Process each tweet returned
  $results = json_decode($connection->response['response']);
  $tweets = $results->statuses;

  // Exit when no more tweets are returned
  if (sizeof($tweets)==0) {
    break;
  }
  foreach($tweets as $tweet) {
    ++$tweets_found;
    $max_id = $tweet->id;
    $oldest_tweet = $tweet->created_at;
  } 
}

print "Tweets found: $tweets_found Oldest tweet: $oldest_tweet";

?&gt;</pre>
<p>It would be great if a group of developers ran this script with their own queries and reported the results. I&#8217;d like to know how many tweets you got back from the API and how far back in time they went. What do you say? Can we start working together to answer questions rather than waiting for answers on the developer mailing list? Tweet your answers to me <a href="http://twitter.com/140dev">@140dev</a>. Thanks for your help. </p>
<p id="ttext">Help me solve the mystery of search API limits.</p>
]]></content:encoded>
			<wfw:commentRss>http://140dev.com/twitter-api-programming-blog/search-api-what-are-the-real-limits-on-tweet-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Search Programming: Secret query operator min_retweets</title>
		<link>http://140dev.com/twitter-api-programming-blog/search-programming-secret-query-operator-min_retweets/</link>
		<comments>http://140dev.com/twitter-api-programming-blog/search-programming-secret-query-operator-min_retweets/#comments</comments>
		<pubDate>Fri, 22 Nov 2013 13:49:06 +0000</pubDate>
		<dc:creator>Adam Green</dc:creator>
				<category><![CDATA[Search API]]></category>

		<guid isPermaLink="false">http://140dev.com/?p=2485</guid>
		<description><![CDATA[Twitter search has been steadily improving since it was acquired from Summize in 2008. At first it returned tweets in a different format from the rest of the API, and had other integration problems, but Twitter has been working on it steadily. I&#8217;m writing a book on search API programming, and the first step is [&#8230;]]]></description>
				<content:encoded><![CDATA[<p></p><p>Twitter search has been steadily improving since it was acquired from Summize in 2008. At first it returned tweets in a different format from the rest of the API, and had other integration problems, but Twitter has been working on it steadily. I&#8217;m writing a book on search API programming, and the first step is testing every possible query option and documenting them on this blog. I thought I&#8217;d start with a very cool operator that isn&#8217;t documented by Twitter. It is <strong>min_retweets</strong>. As the name implies, it will identify tweets that have gotten at least the specified number of retweets. </p>
<p>This is a great form of quality control. I&#8217;m always telling clients that Twitter is a focus group for their messaging, and this option clears out the noise so they can identify the tweets on any subject that have gotten the most reaction. </p>
<p>For example, this search for Obama has no minimum set for retweets:<br />
<a href="https://twitter.com/search?q=obama&#038;src=typd&#038;f=realtime">https://twitter.com/search?q=obama&#038;src=typd&#038;f=realtime</a></p>
<p>Here is the same search for Obama with a min_retweets setting of 100:<br />
<a href="https://twitter.com/search?q=obama%20min_retweets%3A5&#038;src=typd&#038;f=realtime">https://twitter.com/search?q=obama%20min_retweets%3A5&#038;src=typd&#038;f=realtime</a></p>
<p>When I run these two queries, the difference in quality is obvious. Another benefit of min_retweets is that it reveals the most influential users on any subject. Anyone who can get 100 retweets or more has a lot of influence on that subject. </p>
<p>Do you know any secret search operators? I&#8217;d love to hear about them. </p>
]]></content:encoded>
			<wfw:commentRss>http://140dev.com/twitter-api-programming-blog/search-programming-secret-query-operator-min_retweets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exceeding the search API rate limit</title>
		<link>http://140dev.com/twitter-api-programming-blog/exceeding-the-search-api-rate-limit/</link>
		<comments>http://140dev.com/twitter-api-programming-blog/exceeding-the-search-api-rate-limit/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 17:20:13 +0000</pubDate>
		<dc:creator>Adam Green</dc:creator>
				<category><![CDATA[Search API]]></category>

		<guid isPermaLink="false">http://140dev.com/?p=1246</guid>
		<description><![CDATA[We recently built a cool site called This R That for a client. Besides having a great UI that my son, Zach, built, it also has a neat architecture for a Twitter search site. The major weakness of the Twitter search API is that rate limiting is based on the IP making the request. While [&#8230;]]]></description>
				<content:encoded><![CDATA[<p></p><p>We recently built a cool site called <a href="http://thisrth.at">This R That</a> for a client. </p>
<p><a href="http://thisrth.at"><img class="alignleft" src="http://140dev.com/blog_images/thisrthat.png" /></a></p>
<p>Besides having a great UI that my son, Zach, built, it also has a neat architecture for a Twitter search site. The major weakness of the Twitter search API is that rate limiting is based on the IP making the request. While Twitter won&#8217;t reveal the actual limit, it is believed to be about 200 an hour. If you build a web page that takes the search request and sends it to a server to do the work, that server&#8217;s IP will be capped at the rate limit across all users. A popular site would reach that limit fast. </p>
<p>The solution we used was to do the search with Javascript from within the user&#8217;s browser. Then we used Javascript to parse the JSON results and display them as tweet streams. With this model, the IP of the user&#8217;s computer is applied to the rate limit. So each user can do up to 200 search requests every hour, or more if Twitter is feeling generous. Any number of users can be running the same web page simultaneously. </p>
]]></content:encoded>
			<wfw:commentRss>http://140dev.com/twitter-api-programming-blog/exceeding-the-search-api-rate-limit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OK, Twitter. This time you have to fix the Search API</title>
		<link>http://140dev.com/twitter-api-programming-blog/ok-twitter-this-time-you-have-to-fix-the-search-api/</link>
		<comments>http://140dev.com/twitter-api-programming-blog/ok-twitter-this-time-you-have-to-fix-the-search-api/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 15:16:44 +0000</pubDate>
		<dc:creator>Adam Green</dc:creator>
				<category><![CDATA[Search API]]></category>

		<guid isPermaLink="false">http://140dev.com/?p=1121</guid>
		<description><![CDATA[Twitter bought the code for the search API when they acquired Summize, and while it did give them a fast search, I get the feeling they aren&#8217;t too happy about the quality of the code. The biggest hint is that they never fix it. The best example is the documented bug about the search API [&#8230;]]]></description>
				<content:encoded><![CDATA[<p></p><p>Twitter bought the code for the search API when they acquired Summize, and while it did give them a fast search, I get the feeling they aren&#8217;t too happy about the quality of the code. The biggest hint is that they never fix it. The best example is the <a href="http://dev.twitter.com/doc/get/search">documented</a> bug about the search API returning invalid user ids. That&#8217;s right. When you do a search with this API, the id reported for the author of the tweets is often invalid. Not always, but a high percentage. This was added to their bug tracking system <a href="http://code.google.com/p/twitter-api/issues/detail?id=214">2 years ago</a>! Another big issue is the lack of tweet entities in search results. This doesn&#8217;t mean that the search API is worthless. I often use it to get applications going, and there are even some benefits over the streaming API, as I note in my <a href="http://140dev.com/twitter-api-programming-tutorials/aggregating-tweets-search-api-vs-streaming-api/">tutorial </a>on this subject. </p>
<p>Now Twitter has a real problem with search. Sometime last week the ability to use the <code>lang </code>parameter in a search broke. I use it as <code>lang=en</code> to get tweets in English. This has never been 100% effective, but it used to filter out most of the non-English tweets. Throughout the week various uses of the search API with the lang parameter stopped returning any results at all, which I would classify as a serious bug. There were complaints about this all week, but since it was Thanksgiving, nobody at Twitter replied. On Monday they did finally say they were looking at it. </p>
<p>I understand how the Twitter engineers feel. I&#8217;ve been in the position of maintaining and improving acquired code, and it can be a bitch. My development team at Andover.net had the unpleasant task of rewriting the code for Slashdot after we acquired it and we were in the middle of going public. So I sympathize with the problem Twitter faces, but they can&#8217;t push this off to some long-term version 2 solution. If they leave this broken for more than another week, things will get hot, and the press will discover the problem. There are already signs a lot of the MSM is starting to try and tear down what has become a major competitor. This problem is now strategic, not just a wish list item that can be ignored. </p>
<p>Update: Twitter now says this problem is fixed, and my tests show that the lang parameter is now working. Good job. Now about that user_id issue. <img src='http://140dev.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://140dev.com/twitter-api-programming-blog/ok-twitter-this-time-you-have-to-fix-the-search-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Twitter API tutorial comparing search API and streaming API</title>
		<link>http://140dev.com/twitter-api-programming-blog/new-twitter-api-tutorial-comparing-search-api-and-streaming-api/</link>
		<comments>http://140dev.com/twitter-api-programming-blog/new-twitter-api-tutorial-comparing-search-api-and-streaming-api/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 15:34:39 +0000</pubDate>
		<dc:creator>Adam Green</dc:creator>
				<category><![CDATA[Database Cache]]></category>
		<category><![CDATA[Search API]]></category>
		<category><![CDATA[Streaming API]]></category>
		<category><![CDATA[Tweet Aggregation]]></category>

		<guid isPermaLink="false">http://140dev.com/?p=244</guid>
		<description><![CDATA[I just finished a tutorial on the two methods of searching for tweets. Whenever this subject comes up on the Twitter developers mailing list, the usual response is that the streaming API is best, but that depends on your goals and programming ability. If you want to search for tweets in the past, or if [&#8230;]]]></description>
				<content:encoded><![CDATA[<p></p><p>I just finished a tutorial on the two methods of <a href="http://140dev.com/twitter-api-programming-tutorials/aggregating-tweets-search-api-vs-streaming-api/" title="searching for tweets with the Twitter API">searching for tweets</a>. Whenever this subject comes up on the Twitter developers mailing list, the usual response is that the streaming API is best, but that depends on your goals and programming ability. If you want to search for tweets in the past, or if you are not a very experienced programmer, the search API is the right choice. On the other hand, the streaming API will deliver tweets in real-time, which is very impressive for an app. I lay out all the pros and cons <a href="http://140dev.com/twitter-api-programming-tutorials/aggregating-tweets-search-api-vs-streaming-api/" title="searching for tweets with the Twitter API">here</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://140dev.com/twitter-api-programming-blog/new-twitter-api-tutorial-comparing-search-api-and-streaming-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
