Zend_Service_Twitter.xml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.service.twitter" xmlns:xi="http://www.w3.org/2001/XInclude">
  4. <title>Zend_Service_Twitter</title>
  5. <sect2 id="zend.service.twitter.introduction">
  6. <title>Introduction</title>
  7. <para>
  8. <classname>Zend_Service_Twitter</classname> provides a client for the <ulink
  9. url="http://apiwiki.twitter.com/REST+API+Documentation">Twitter REST API</ulink>.
  10. <classname>Zend_Service_Twitter</classname> will allow you to query the public timeline and if you provide a username
  11. and password for Twitter it will allow you to get and update your status, reply to friends,
  12. direct message friends, mark tweets as favorite and much more.
  13. </para>
  14. <para>
  15. <classname>Zend_Service_Twitter</classname> is implementing a REST service and all methods return an instance of
  16. <classname>Zend_Rest_Client_Result</classname>.
  17. </para>
  18. <para>
  19. <classname>Zend_Service_Twitter</classname> is broken up into subsections so you can easily identify which type of call
  20. is being requested.
  21. </para>
  22. <itemizedlist>
  23. <listitem>
  24. <para>
  25. <code>account</code>, make sure that your account credentials are valid, check your api rate limit
  26. and end the current session for the authenticated user.
  27. </para>
  28. </listitem>
  29. <listitem>
  30. <para>
  31. <code>status</code>, retrieves the public and user timelines and allows you to show, update, destroy
  32. and retrieve replies for the authenticated user.
  33. </para>
  34. </listitem>
  35. <listitem>
  36. <para>
  37. <code>user</code>, retrieves the friends, followers for the authenticated user. With the
  38. show method you can return extended information about the passed in user.
  39. </para>
  40. </listitem>
  41. <listitem>
  42. <para>
  43. <code>directMessage</code>, retrieves the authenticated users received direct message and allows you to send and
  44. delete new direct message.
  45. </para>
  46. </listitem>
  47. <listitem>
  48. <para>
  49. <code>friendship</code>, create or remove a friendship for the authenticated user.
  50. </para>
  51. </listitem>
  52. <listitem>
  53. <para>
  54. <code>favorite</code>, list, create or remove a favorite tweet.
  55. </para>
  56. </listitem>
  57. </itemizedlist>
  58. </sect2>
  59. <sect2 id="zend.service.twitter.authentication">
  60. <title>Authentication</title>
  61. <para>
  62. With the exception of fetching the public timeline <classname>Zend_Service_Twitter</classname> requires
  63. authentication to work. Twitter currently uses <ulink
  64. url="http://en.wikipedia.org/wiki/Basic_authentication_scheme">HTTP Basic Authentication</ulink>.
  65. You can pass in your username or registered email along with your password for twitter to login.
  66. </para>
  67. <example id="zend.service.twitter.authentication.example">
  68. <title>Creating the Twitter Class</title>
  69. <para>
  70. The following code sample is how you create the Twitter Service and pass in your username and password
  71. and then verify that they are correct.
  72. </para>
  73. <programlisting language="php"><![CDATA[
  74. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  75. // verify your credentials with twitter
  76. $response = $twitter->account->verifyCredentials();
  77. ]]></programlisting>
  78. </example>
  79. </sect2>
  80. <sect2 id="zend.service.twitter.accout">
  81. <title>Account Methods</title>
  82. <itemizedlist>
  83. <listitem>
  84. <para>
  85. <code>verifyCredentials</code>, Use this method to test if supplied user credentials are valid with minimal overhead.
  86. </para>
  87. <example id="zend.service.twitter.account.verifycredentails">
  88. <title>Verifying credentials</title>
  89. <programlisting language="php"><![CDATA[
  90. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  91. $response = $twitter->account->verifyCredentials();
  92. ]]></programlisting>
  93. </example>
  94. </listitem>
  95. <listitem>
  96. <para>
  97. <code>endSession</code>, Use this method to sign users out of client-facing applications.
  98. </para>
  99. <example id="zend.service.twitter.account.endsession">
  100. <title>Sessions ending</title>
  101. <programlisting language="php"><![CDATA[
  102. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  103. $response = $twitter->account->endSession();
  104. ]]></programlisting>
  105. </example>
  106. </listitem>
  107. <listitem>
  108. <para>
  109. <code>rateLimitStatus</code>, Returns the remaining number of API requests available to the authenticating user
  110. before the API limit is reached for the current hour.
  111. </para>
  112. <example id="zend.service.twitter.account.ratelimitstatus">
  113. <title>Rating limit status</title>
  114. <programlisting language="php"><![CDATA[
  115. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  116. $response = $twitter->account->rateLimitStatus();
  117. ]]></programlisting>
  118. </example>
  119. </listitem>
  120. </itemizedlist>
  121. </sect2>
  122. <sect2 id="zend.service.twitter.status">
  123. <title>Status Methods</title>
  124. <itemizedlist>
  125. <listitem>
  126. <para>
  127. <code>publicTimeline</code>, Returns the 20 most recent statuses from non-protected users with a custom user icon.
  128. The public timeline is cached by twitter for 60 seconds.
  129. </para>
  130. <example id="zend.service.twitter.status.publictimeline">
  131. <title>Retrieving public timeline</title>
  132. <programlisting language="php"><![CDATA[
  133. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  134. $response = $twitter->status->publicTimeline();
  135. ]]></programlisting>
  136. </example>
  137. </listitem>
  138. <listitem>
  139. <para>
  140. <code>friendsTimeline</code>, Returns the 20 most recent statuses posted by the authenticating user and that
  141. user's friends.
  142. </para>
  143. <example id="zend.service.twitter.status.friendstimeline">
  144. <title>Retrieving friends timeline</title>
  145. <programlisting language="php"><![CDATA[
  146. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  147. $response = $twitter->status->friendsTimeline();
  148. ]]></programlisting>
  149. </example>
  150. <para>The <code>friendsTimeline</code> method accepts an array of optional parameters to modify the query.</para>
  151. <itemizedlist>
  152. <listitem>
  153. <para>
  154. <code>since</code>, Narrows the returned results to just those statuses created after the specified
  155. date/time (up to 24 hours old).
  156. </para>
  157. </listitem>
  158. <listitem>
  159. <para>
  160. <code>page</code>, Which page you want to return.
  161. </para>
  162. </listitem>
  163. </itemizedlist>
  164. </listitem>
  165. <listitem>
  166. <para>
  167. <code>userTimeline</code>, Returns the 20 most recent statuses posted from the authenticating user.
  168. </para>
  169. <example id="zend.service.twitter.status.usertimeline">
  170. <title>Retrieving user timeline</title>
  171. <programlisting language="php"><![CDATA[
  172. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  173. $response = $twitter->status->userTimeline();
  174. ]]></programlisting>
  175. </example>
  176. <para>The <code>userTimeline</code> method accepts an array of optional parameters to modify the query.</para>
  177. <itemizedlist>
  178. <listitem>
  179. <para>
  180. <code>id</code>, Specifies the ID or screen name of the user for whom to return the friends_timeline.
  181. </para>
  182. </listitem>
  183. <listitem>
  184. <para>
  185. <code>since</code>, Narrows the returned results to just those statuses created after the specified
  186. date/time (up to 24 hours old).
  187. </para>
  188. </listitem>
  189. <listitem>
  190. <para>
  191. <code>page</code>, Which page you want to return.
  192. </para>
  193. </listitem>
  194. <listitem>
  195. <para>
  196. <code>count</code>, Specifies the number of statuses to retrieve. May not be greater than 200.
  197. </para>
  198. </listitem>
  199. </itemizedlist>
  200. </listitem>
  201. <listitem>
  202. <para>
  203. <code>show</code>, Returns a single status, specified by the id parameter below. The status's author will be returned inline.
  204. This method required a tweet id to be passed in.
  205. </para>
  206. <example id="zend.service.twitter.status.show">
  207. <title>Showing user status</title>
  208. <programlisting language="php"><![CDATA[
  209. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  210. $response = $twitter->status->show(1234);
  211. ]]></programlisting>
  212. </example>
  213. </listitem>
  214. <listitem>
  215. <para>
  216. <code>update</code>, Updates the authenticating user's status. This method requires that you pass in the status update that
  217. you want to post to twitter. A second optional parameter is the id of the tweet that you are replying to.
  218. </para>
  219. <example id="zend.service.twitter.status.update">
  220. <title>Updating user status</title>
  221. <programlisting language="php"><![CDATA[
  222. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  223. $response = $twitter->status->update('My Great Tweet');
  224. ]]></programlisting>
  225. </example>
  226. <para>The <code>update</code> method accepts a second additional parameter.</para>
  227. <itemizedlist>
  228. <listitem>
  229. <para>
  230. <code>in_reply_to_status_id</code>, The ID of an existing status that the status to be posted is in reply to.
  231. </para>
  232. </listitem>
  233. </itemizedlist>
  234. </listitem>
  235. <listitem>
  236. <para>
  237. <code>replies</code>, Returns the 20 most recent @replies (status updates prefixed with @username) for the
  238. authenticating user.
  239. </para>
  240. <example id="zend.service.twitter.status.replies">
  241. <title>Showing user replies</title>
  242. <programlisting language="php"><![CDATA[
  243. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  244. $response = $twitter->status->replies();
  245. ]]></programlisting>
  246. </example>
  247. <para>The <code>replies</code> method accepts an array of optional parameters to modify the query.</para>
  248. <itemizedlist>
  249. <listitem>
  250. <para>
  251. <code>since</code>, Narrows the returned results to just those statuses created after the specified
  252. date/time (up to 24 hours old).
  253. </para>
  254. </listitem>
  255. <listitem>
  256. <para>
  257. <code>page</code>, Which page you want to return.
  258. </para>
  259. </listitem>
  260. <listitem>
  261. <para>
  262. <code>since_id</code>, Returns only statuses with an ID greater than (that is, more recent than) the specified ID.
  263. </para>
  264. </listitem>
  265. </itemizedlist>
  266. </listitem>
  267. <listitem>
  268. <para>
  269. <code>destroy</code>, Destroys the status specified by the required ID parameter.
  270. </para>
  271. <example id="zend.service.twitter.status.destroy">
  272. <title>Deleting user status</title>
  273. <programlisting language="php"><![CDATA[
  274. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  275. $response = $twitter->status->destroy(12345);
  276. ]]></programlisting>
  277. </example>
  278. </listitem>
  279. </itemizedlist>
  280. </sect2>
  281. <sect2 id="zend.service.twitter.user">
  282. <title>User Methods</title>
  283. <itemizedlist>
  284. <listitem>
  285. <para>
  286. <code>friends</code>, Returns up to 100 of the authenticating user's friends who have
  287. most recently updated, each with current status inline.
  288. </para>
  289. <example id="zend.service.twitter.user.friends">
  290. <title>Retrieving user friends</title>
  291. <programlisting language="php"><![CDATA[
  292. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  293. $response = $twitter->user->friends();
  294. ]]></programlisting>
  295. </example>
  296. <para>The <code>friends</code> method accepts an array of optional parameters to modify the query.</para>
  297. <itemizedlist>
  298. <listitem>
  299. <para>
  300. <code>id</code>, Specifies the ID or screen name of the user for whom to return a list of friends.
  301. </para>
  302. </listitem>
  303. <listitem>
  304. <para>
  305. <code>since</code>, Narrows the returned results to just those statuses created after the specified
  306. date/time (up to 24 hours old).
  307. </para>
  308. </listitem>
  309. <listitem>
  310. <para>
  311. <code>page</code>, Which page you want to return.
  312. </para>
  313. </listitem>
  314. </itemizedlist>
  315. </listitem>
  316. <listitem>
  317. <para>
  318. <code>followers</code>, Returns the authenticating user's followers, each with current status inline.
  319. </para>
  320. <example id="zend.service.twitter.user.followers">
  321. <title>Retrieving user followers</title>
  322. <programlisting language="php"><![CDATA[
  323. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  324. $response = $twitter->user->followers();
  325. ]]></programlisting>
  326. </example>
  327. <para>The <code>followers</code> method accepts an array of optional parameters to modify the query.</para>
  328. <itemizedlist>
  329. <listitem>
  330. <para>
  331. <code>id</code>, Specifies the ID or screen name of the user for whom to return a list of followers.
  332. </para>
  333. </listitem>
  334. <listitem>
  335. <para>
  336. <code>page</code>, Which page you want to return.
  337. </para>
  338. </listitem>
  339. </itemizedlist>
  340. </listitem>
  341. <listitem>
  342. <para>
  343. <code>show</code>, Returns extended information of a given user, specified by ID or screen name as per the
  344. required id parameter below
  345. </para>
  346. <example id="zend.service.twitter.user.show">
  347. <title>Showing user informations</title>
  348. <programlisting language="php"><![CDATA[
  349. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  350. $response = $twitter->user->show('myfriend');
  351. ]]></programlisting>
  352. </example>
  353. </listitem>
  354. </itemizedlist>
  355. </sect2>
  356. <sect2 id="zend.service.twitter.directmessage">
  357. <title>Direct Message Methods</title>
  358. <itemizedlist>
  359. <listitem>
  360. <para>
  361. <code>messages</code>, Returns a list of the 20 most recent direct messages sent to the authenticating user.
  362. </para>
  363. <example id="zend.service.twitter.directmessage.messages">
  364. <title>Retrieving recent direct messages received</title>
  365. <programlisting language="php"><![CDATA[
  366. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  367. $response = $twitter->directMessage->messages();
  368. ]]></programlisting>
  369. </example>
  370. <para>The <code>message</code> method accepts an array of optional parameters to modify the query.</para>
  371. <itemizedlist>
  372. <listitem>
  373. <para>
  374. <code>since_id</code>, Returns only direct messages with an ID greater than (that is, more recent than)
  375. the specified ID.
  376. </para>
  377. </listitem>
  378. <listitem>
  379. <para>
  380. <code>since</code>, Narrows the returned results to just those statuses created after the specified
  381. date/time (up to 24 hours old).
  382. </para>
  383. </listitem>
  384. <listitem>
  385. <para>
  386. <code>page</code>, Which page you want to return.
  387. </para>
  388. </listitem>
  389. </itemizedlist>
  390. </listitem>
  391. <listitem>
  392. <para>
  393. <code>sent</code>, Returns a list of the 20 most recent direct messages sent by the authenticating user.
  394. </para>
  395. <example id="zend.service.twitter.directmessage.sent">
  396. <title>Retrieving recent direct messages sent</title>
  397. <programlisting language="php"><![CDATA[
  398. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  399. $response = $twitter->directMessage->sent();
  400. ]]></programlisting>
  401. </example>
  402. <para>The <code>sent</code> method accepts an array of optional parameters to modify the query.</para>
  403. <itemizedlist>
  404. <listitem>
  405. <para>
  406. <code>since_id</code>, Returns only direct messages with an ID greater than (that is, more recent than)
  407. the specified ID.
  408. </para>
  409. </listitem>
  410. <listitem>
  411. <para>
  412. <code>since</code>, Narrows the returned results to just those statuses created after the specified
  413. date/time (up to 24 hours old).
  414. </para>
  415. </listitem>
  416. <listitem>
  417. <para>
  418. <code>page</code>, Which page you want to return.
  419. </para>
  420. </listitem>
  421. </itemizedlist>
  422. </listitem>
  423. <listitem>
  424. <para>
  425. <code>new</code>, Sends a new direct message to the specified user from the authenticating user.
  426. Requires both the user and text parameters below.
  427. </para>
  428. <example id="zend.service.twitter.directmessage.new">
  429. <title>Sending direct message</title>
  430. <programlisting language="php"><![CDATA[
  431. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  432. $response = $twitter->directMessage->new('myfriend', 'mymessage');
  433. ]]></programlisting>
  434. </example>
  435. </listitem>
  436. <listitem>
  437. <para>
  438. <code>destroy</code>, Destroys the direct message specified in the required ID parameter. The authenticating user
  439. must be the recipient of the specified direct message.
  440. </para>
  441. <example id="zend.service.twitter.directmessage.destroy">
  442. <title>Deleting direct message</title>
  443. <programlisting language="php"><![CDATA[
  444. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  445. $response = $twitter->directMessage->destroy(123548);
  446. ]]></programlisting>
  447. </example>
  448. </listitem>
  449. </itemizedlist>
  450. </sect2>
  451. <sect2 id="zend.service.twitter.friendship">
  452. <title>Friendship Methods</title>
  453. <itemizedlist>
  454. <listitem>
  455. <para>
  456. <code>create</code>, Befriends the user specified in the ID parameter as the authenticating user.
  457. </para>
  458. <example id="zend.service.twitter.friendship.create">
  459. <title>Creating friend</title>
  460. <programlisting language="php"><![CDATA[
  461. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  462. $response = $twitter->friendship->create('mynewfriend');
  463. ]]></programlisting>
  464. </example>
  465. </listitem>
  466. <listitem>
  467. <para>
  468. <code>destroy</code>, Discontinues friendship with the user specified in the ID parameter as the authenticating user.
  469. </para>
  470. <example id="zend.service.twitter.friendship.destroy">
  471. <title>Deleting friend</title>
  472. <programlisting language="php"><![CDATA[
  473. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  474. $response = $twitter->friendship->destroy('myoldfriend');
  475. ]]></programlisting>
  476. </example>
  477. </listitem>
  478. <listitem>
  479. <para>
  480. <code>exists</code>, Tests if a friendship exists between the authenticated user and the passed in user.
  481. </para>
  482. <example id="zend.service.twitter.friendship.exists">
  483. <title>Checking friend existence</title>
  484. <programlisting language="php"><![CDATA[
  485. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  486. $response = $twitter->friendship->exists('myfriend');
  487. ]]></programlisting>
  488. </example>
  489. </listitem>
  490. </itemizedlist>
  491. </sect2>
  492. <sect2 id="zend.service.twitter.favorite">
  493. <title>Favorite Methods</title>
  494. <itemizedlist>
  495. <listitem>
  496. <para>
  497. <code>favorites</code>, Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter
  498. </para>
  499. <example id="zend.service.twitter.favorite.favorites">
  500. <title>Retrieving favorites</title>
  501. <programlisting language="php"><![CDATA[
  502. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  503. $response = $twitter->favorite->favorites();
  504. ]]></programlisting>
  505. </example>
  506. <itemizedlist>
  507. <listitem>
  508. <para>
  509. <code>id</code>, The ID or screen name of the user for whom to request a list of favorite statuses.
  510. </para>
  511. </listitem>
  512. <listitem>
  513. <para>
  514. <code>page</code>, Which page you want to return.
  515. </para>
  516. </listitem>
  517. </itemizedlist>
  518. </listitem>
  519. <listitem>
  520. <para>
  521. <code>create</code>, Favorites the status specified in the ID parameter as the authenticating user..
  522. </para>
  523. <example id="zend.service.twitter.favorite.create">
  524. <title>Creating favorites</title>
  525. <programlisting language="php"><![CDATA[
  526. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  527. $response = $twitter->favorite->create(12351);
  528. ]]></programlisting>
  529. </example>
  530. </listitem>
  531. <listitem>
  532. <para>
  533. <code>destroy</code>, Un-favorites the status specified in the ID parameter as the authenticating user.
  534. </para>
  535. <example id="zend.service.twitter.favorite.destroy">
  536. <title>Deleting favorites</title>
  537. <programlisting language="php"><![CDATA[
  538. $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
  539. $response = $twitter->favorite->destroy(12351);
  540. ]]></programlisting>
  541. </example>
  542. </listitem>
  543. </itemizedlist>
  544. </sect2>
  545. <xi:include href="Zend_Service_Twitter_Search.xml" />
  546. </sect1>
  547. <!--
  548. vim:se ts=4 sw=4 et:
  549. -->