Zend_Service_Twitter_Search.xml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect2 id="zend.service.twitter.search">
  4. <title>Zend_Service_Twitter_Search</title>
  5. <sect3 id="zend.service.twitter.search.introduction">
  6. <title>Introduction</title>
  7. <para>
  8. <classname>Zend_Service_Twitter_Search</classname> provides a client for the <ulink
  9. url="http://apiwiki.twitter.com/Search+API+Documentation">Twitter Search API</ulink>.
  10. The Twitter Search service is use to search Twitter. Currently it only
  11. returns data in Atom or JSON format but a full REST service is in the future
  12. which will support XML responses.
  13. </para>
  14. </sect3>
  15. <sect3 id="zend.service.twitter.search.trends">
  16. <title>Twitter Trends</title>
  17. <para>
  18. Returns the top ten queries that are currently trending on Twitter.
  19. The response includes the time of the request, the name of each trending topic,
  20. and the url to the Twitter Search results page for that topic.
  21. Currently the search API for trends only supports a JSON return so the function returns
  22. an array.
  23. </para>
  24. <programlisting language="php"><![CDATA[
  25. $twitter_search = new Zend_Service_Twitter_Search();
  26. $twitter_trends = $twitter_search->trends();
  27. foreach($twitter_trends as $trend) {
  28. print $trend['name'] . ' - ' . $trend['url'] . PHP_EOL
  29. }
  30. ]]></programlisting>
  31. <para>
  32. The return array has two values in it:
  33. </para>
  34. <itemizedlist>
  35. <listitem>
  36. <para>
  37. <code>name</code>, the name of trend.
  38. </para>
  39. </listitem>
  40. <listitem>
  41. <para>
  42. <code>url</code>, the url to see the tweets
  43. for that trend.
  44. </para>
  45. </listitem>
  46. </itemizedlist>
  47. </sect3>
  48. <sect3 id="zend.service.twitter.search.search">
  49. <title>Searching Twitter</title>
  50. <para>
  51. Using the search method returns tweets that match a specific query.
  52. There are a number of <ulink
  53. url="http://search.twitter.com/operators">Search Operators</ulink> that you
  54. can use to query with.
  55. </para>
  56. <para>
  57. The search method can accept six different optional URL parameters passed in as an array:
  58. </para>
  59. <itemizedlist>
  60. <listitem>
  61. <para>
  62. <code>lang</code>, restricts the tweets to a given language, lang must
  63. be given by an <ulink url="http://en.wikipedia.org/wiki/ISO_639-1">ISO 639-1 code</ulink>.
  64. </para>
  65. </listitem>
  66. <listitem>
  67. <para>
  68. <code>rpp</code>, the number of tweets to return per page,
  69. up to a max of 100.
  70. </para>
  71. </listitem>
  72. <listitem>
  73. <para>
  74. <code>page</code>, the page number to return, up to a max of
  75. roughly 1500 results (based on rpp * page)
  76. </para>
  77. </listitem>
  78. <listitem>
  79. <para>
  80. <code>since_id</code>, returns tweets with status ids
  81. greater than the given id.
  82. </para>
  83. </listitem>
  84. <listitem>
  85. <para>
  86. <code>show_user</code>, when "true", adds "&gt;user&lt;:"
  87. to the beginning of the tweet. This is useful for readers
  88. that do not display Atom's author field. The default is "false"
  89. </para>
  90. </listitem>
  91. <listitem>
  92. <para>
  93. <code>geocode</code>, returns tweets by users located within a given radius of the given
  94. latitude/longitude, where the user's location is taken from their Twitter profile. The
  95. parameter value is specified by "latitude,longitude,radius", where radius units must
  96. be specified as either "mi" (miles) or "km" (kilometers).
  97. </para>
  98. </listitem>
  99. </itemizedlist>
  100. <example id="zend.service.twitter.search.search.json">
  101. <title>JSON Search Example</title>
  102. <para>
  103. The following code sample will return an array with the values search results
  104. </para>
  105. <programlisting language="php"><![CDATA[
  106. $twitter_search = new Zend_Service_Twitter_Search('json');
  107. $search_results = $twitter_search->search('zend', array('lang' => 'en'));
  108. ]]></programlisting>
  109. </example>
  110. <example id="zend.service.twitter.search.search.atom">
  111. <title>ATOM Search Example</title>
  112. <para>
  113. The following code sample will return a <classname>Zend_Feed_Atom</classname> object.
  114. </para>
  115. <programlisting language="php"><![CDATA[
  116. $twitter_search = new Zend_Service_Twitter_Search('atom');
  117. $search_results = $twitter_search->search('zend', array('lang' => 'en'));
  118. ]]></programlisting>
  119. </example>
  120. </sect3>
  121. <sect3 id="zend.service.twitter.search.accessors">
  122. <title>Zend-specific Accessor Methods</title>
  123. <para>
  124. While the Twitter Search API only specifies two methods,
  125. <classname>Zend_Service_Twitter_Search</classname> has additional accessors
  126. that may be used for modifying internal properties.
  127. </para>
  128. <itemizedlist>
  129. <listitem>
  130. <para>
  131. <code>getResponseType()</code> and <code>setResponseType()</code>
  132. allow you to retrieve and modify the response type of the search
  133. between JSON and ATOM.
  134. </para>
  135. </listitem>
  136. </itemizedlist>
  137. </sect3>
  138. </sect2>
  139. <!--
  140. vim:se ts=4 sw=4 et:
  141. -->