Zend_Service_Twitter.xml 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  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
  9. <ulink url="http://apiwiki.twitter.com/Twitter-API-Documentation">Twitter
  10. <acronym>REST</acronym> <acronym>API</acronym></ulink>.
  11. <classname>Zend_Service_Twitter</classname> allows you to query the public timeline. If
  12. you provide a username and OAuth details for Twitter, it will allow you to get and update
  13. your status, reply to friends, direct message friends, mark tweets as favorite, and
  14. much more.
  15. </para>
  16. <para>
  17. <classname>Zend_Service_Twitter</classname> implements a <acronym>REST</acronym>
  18. service, and all methods return an instance of
  19. <classname>Zend_Rest_Client_Result</classname>.
  20. </para>
  21. <para>
  22. <classname>Zend_Service_Twitter</classname> is broken up into subsections so you can
  23. easily identify which type of call is being requested.
  24. </para>
  25. <itemizedlist>
  26. <listitem>
  27. <para>
  28. <code>account</code> makes sure that your account credentials are valid, checks
  29. your <acronym>API</acronym> rate limit, and ends the current session for the
  30. authenticated user.
  31. </para>
  32. </listitem>
  33. <listitem>
  34. <para>
  35. <code>status</code> retrieves the public and user timelines and
  36. shows, updates, destroys, and retrieves replies for the authenticated user.
  37. </para>
  38. </listitem>
  39. <listitem>
  40. <para>
  41. <code>user</code> retrieves friends and followers for the authenticated user
  42. and returns extended information about a passed user.
  43. </para>
  44. </listitem>
  45. <listitem>
  46. <para>
  47. <code>directMessage</code> retrieves the authenticated user's received direct
  48. messages, deletes direct messages, and sends new direct messages.
  49. </para>
  50. </listitem>
  51. <listitem>
  52. <para>
  53. <code>friendship</code> creates and removes friendships for the
  54. authenticated user.
  55. </para>
  56. </listitem>
  57. <listitem>
  58. <para>
  59. <code>favorite</code> lists, creates, and removes favorite tweets.
  60. </para>
  61. </listitem>
  62. <listitem>
  63. <para>
  64. <code>block</code> blocks and unblocks users from following you.
  65. </para>
  66. </listitem>
  67. </itemizedlist>
  68. </sect2>
  69. <sect2 id="zend.service.twitter.authentication">
  70. <title>Authentication</title>
  71. <para>
  72. With the exception of fetching the public timeline,
  73. <classname>Zend_Service_Twitter</classname> requires authentication as a valid
  74. user. This is achieved using the OAuth authentication protocol. OAuth is
  75. the only supported authentication mode for Twitter as of August 2010. The OAuth
  76. implementation used by <classname>Zend_Service_Twitter</classname> is
  77. <classname>Zend_Oauth</classname>.
  78. </para>
  79. <example id="zend.service.twitter.authentication.example">
  80. <title>Creating the Twitter Class</title>
  81. <para>
  82. <classname>Zend_Service_Twitter</classname> must authorize itself, on behalf of a user, before use with the
  83. Twitter API (except for public timeline). This must be accomplished using OAuth since
  84. Twitter has disabled it's basic HTTP authentication as of August 2010.
  85. </para>
  86. <para>
  87. There are two options to establishing authorization. The first is to implement the
  88. workflow of <classname>Zend_Oauth</classname> via <classname>Zend_Service_Twitter</classname>
  89. which proxies to an internal <classname>Zend_Oauth_Consumer</classname> object. Please refer to
  90. the <classname>Zend_Oauth</classname> documentation for a full example of this
  91. workflow - you can call all documented <classname>Zend_Oauth_Consumer</classname> methods
  92. on <classname>Zend_Service_Twitter</classname> including constructor options. You may also
  93. use <classname>Zend_Oauth</classname> directly and only pass the resulting access
  94. token into <classname>Zend_Service_Twitter</classname>. This is the normal workflow
  95. once you have established a reusable access token for a particular Twitter user. The resulting OAuth
  96. access token should be stored to a database for future use (otherwise you will need to
  97. authorize for every new instance of <classname>Zend_Service_Twitter</classname>). Bear in mind
  98. that authorization via OAuth results in your user being redirected to Twitter to give their
  99. consent to the requested authorization (this is not repeated for stored access tokens). This will
  100. require additional work (i.e. redirecting users and hosting a callback URL) over the previous
  101. HTTP authentication mechanism where a user just
  102. needed to allow applications to store their username and password.
  103. </para>
  104. <para>The following example demonstrates setting up <classname>Zend_Service_Twitter</classname>
  105. which is given an already established OAuth access token. Please refer to the <classname>Zend_Oauth</classname>
  106. documentation to understand the workflow involved. The access token is a serializable object, so you may
  107. store the serialized object to a database, and unserialize it at retrieval time before passing the objects
  108. into <classname>Zend_Service_Twitter</classname>. The <classname>Zend_Oauth</classname> documentation
  109. demonstrates the workflow and objects involved.</para>
  110. <programlisting language="php"><![CDATA[
  111. /**
  112. * We assume $serializedToken is the serialized token retrieved from a database
  113. * or even $_SESSION (if following the simple Zend_Oauth documented example)
  114. */
  115. $token = unserialize($serializedToken);
  116. $twitter = new Zend_Service_Twitter(array(
  117. 'username' => 'johndoe',
  118. 'accessToken' => $token
  119. ));
  120. // verify user's credentials with Twitter
  121. $response = $twitter->account->verifyCredentials();
  122. ]]></programlisting>
  123. </example>
  124. <note>
  125. <para>
  126. In order to authenticate with Twitter, ALL applications MUST be registered with
  127. Twitter in order to receive a Consumer Key and Consumer Secret to be used when
  128. authenticating with OAuth. This can not be reused across multiple applications -
  129. you must register each new application separately. Twitter access tokens have
  130. no expiry date, so storing them to a database is advised (they can, of course,
  131. be refreshed simply be repeating the OAuth authorization process). This can only
  132. be done while interacting with the user associated with that access token.
  133. </para>
  134. <para>
  135. The previous pre-OAuth version of <classname>Zend_Service_Twitter</classname>
  136. allowed passing in a username as the first parameter rather than within an array.
  137. This is no longer supported.
  138. </para>
  139. </note>
  140. </sect2>
  141. <sect2 id="zend.service.twitter.account">
  142. <title>Account Methods</title>
  143. <itemizedlist>
  144. <listitem>
  145. <para>
  146. <methodname>verifyCredentials()</methodname> tests if supplied user
  147. credentials are valid with minimal overhead.
  148. </para>
  149. <example id="zend.service.twitter.account.verifycredentails">
  150. <title>Verifying credentials</title>
  151. <programlisting language="php"><![CDATA[
  152. $twitter = new Zend_Service_Twitter(array(
  153. 'username' => 'johndoe',
  154. 'accessToken' => $token
  155. ));
  156. $response = $twitter->account->verifyCredentials();
  157. ]]></programlisting>
  158. </example>
  159. </listitem>
  160. <listitem>
  161. <para>
  162. <methodname>endSession()</methodname> signs users out of
  163. client-facing applications.
  164. </para>
  165. <example id="zend.service.twitter.account.endsession">
  166. <title>Sessions ending</title>
  167. <programlisting language="php"><![CDATA[
  168. $twitter = new Zend_Service_Twitter(array(
  169. 'username' => 'johndoe',
  170. 'accessToken' => $token
  171. ));
  172. $response = $twitter->account->endSession();
  173. ]]></programlisting>
  174. </example>
  175. </listitem>
  176. <listitem>
  177. <para>
  178. <methodname>rateLimitStatus()</methodname> returns the remaining number of
  179. <acronym>API</acronym> requests available to the authenticating user
  180. before the <acronym>API</acronym> limit is reached for the current hour.
  181. </para>
  182. <example id="zend.service.twitter.account.ratelimitstatus">
  183. <title>Rating limit status</title>
  184. <programlisting language="php"><![CDATA[
  185. $twitter = new Zend_Service_Twitter(array(
  186. 'username' => 'johndoe',
  187. 'accessToken' => $token
  188. ));
  189. $response = $twitter->account->rateLimitStatus();
  190. ]]></programlisting>
  191. </example>
  192. </listitem>
  193. </itemizedlist>
  194. </sect2>
  195. <sect2 id="zend.service.twitter.status">
  196. <title>Status Methods</title>
  197. <itemizedlist>
  198. <listitem>
  199. <para>
  200. <methodname>publicTimeline()</methodname> returns the 20 most recent statuses
  201. from non-protected users with a custom user icon. The public timeline is cached
  202. by Twitter for 60 seconds.
  203. </para>
  204. <example id="zend.service.twitter.status.publictimeline">
  205. <title>Retrieving public timeline</title>
  206. <programlisting language="php"><![CDATA[
  207. $twitter = new Zend_Service_Twitter(array(
  208. 'username' => 'johndoe',
  209. 'accessToken' => $token
  210. ));
  211. $response = $twitter->status->publicTimeline();
  212. ]]></programlisting>
  213. </example>
  214. </listitem>
  215. <listitem>
  216. <para>
  217. <methodname>friendsTimeline()</methodname> returns the 20 most recent statuses
  218. posted by the authenticating user and that user's friends.
  219. </para>
  220. <example id="zend.service.twitter.status.friendstimeline">
  221. <title>Retrieving friends timeline</title>
  222. <programlisting language="php"><![CDATA[
  223. $twitter = new Zend_Service_Twitter(array(
  224. 'username' => 'johndoe',
  225. 'accessToken' => $token
  226. ));
  227. $response = $twitter->status->friendsTimeline();
  228. ]]></programlisting>
  229. </example>
  230. <para>
  231. The <methodname>friendsTimeline()</methodname> method accepts an array of
  232. optional parameters to modify the query.
  233. </para>
  234. <itemizedlist>
  235. <listitem>
  236. <para>
  237. <code>since</code> narrows the returned results to just those statuses
  238. created after the specified date/time (up to 24 hours old).
  239. </para>
  240. </listitem>
  241. <listitem>
  242. <para>
  243. <code>page</code> specifies which page you want to return.
  244. </para>
  245. </listitem>
  246. </itemizedlist>
  247. </listitem>
  248. <listitem>
  249. <para>
  250. <methodname>userTimeline()</methodname> returns the 20 most recent statuses
  251. posted from the authenticating user.
  252. </para>
  253. <example id="zend.service.twitter.status.usertimeline">
  254. <title>Retrieving user timeline</title>
  255. <programlisting language="php"><![CDATA[
  256. $twitter = new Zend_Service_Twitter(array(
  257. 'username' => 'johndoe',
  258. 'accessToken' => $token
  259. ));
  260. $response = $twitter->status->userTimeline();
  261. ]]></programlisting>
  262. </example>
  263. <para>
  264. The <methodname>userTimeline()</methodname> method accepts an array of optional
  265. parameters to modify the query.
  266. </para>
  267. <itemizedlist>
  268. <listitem>
  269. <para>
  270. <code>id</code> specifies the ID or screen name of the user for whom to
  271. return the friends_timeline.
  272. </para>
  273. </listitem>
  274. <listitem>
  275. <para>
  276. <code>since</code> narrows the returned results to just those statuses
  277. created after the specified date/time (up to 24 hours old).
  278. </para>
  279. </listitem>
  280. <listitem>
  281. <para>
  282. <code>page</code> specifies which page you want to return.
  283. </para>
  284. </listitem>
  285. <listitem>
  286. <para>
  287. <code>count</code> specifies the number of statuses to retrieve.
  288. May not be greater than 200.
  289. </para>
  290. </listitem>
  291. </itemizedlist>
  292. </listitem>
  293. <listitem>
  294. <para>
  295. <methodname>show()</methodname> returns a single status, specified by the
  296. <code>id</code> parameter below. The status' author will be returned inline.
  297. </para>
  298. <example id="zend.service.twitter.status.show">
  299. <title>Showing user status</title>
  300. <programlisting language="php"><![CDATA[
  301. $twitter = new Zend_Service_Twitter(array(
  302. 'username' => 'johndoe',
  303. 'accessToken' => $token
  304. ));
  305. $response = $twitter->status->show(1234);
  306. ]]></programlisting>
  307. </example>
  308. </listitem>
  309. <listitem>
  310. <para>
  311. <methodname>update()</methodname> updates the authenticating user's status.
  312. This method requires that you pass in the status update that you want to post
  313. to Twitter.
  314. </para>
  315. <example id="zend.service.twitter.status.update">
  316. <title>Updating user status</title>
  317. <programlisting language="php"><![CDATA[
  318. $twitter = new Zend_Service_Twitter(array(
  319. 'username' => 'johndoe',
  320. 'accessToken' => $token
  321. ));
  322. $response = $twitter->status->update('My Great Tweet');
  323. ]]></programlisting>
  324. </example>
  325. <para>
  326. The <methodname>update()</methodname> method accepts a second additional
  327. parameter.
  328. </para>
  329. <itemizedlist>
  330. <listitem>
  331. <para>
  332. <code>in_reply_to_status_id</code> specifies the ID of an existing
  333. status that the status to be posted is in reply to.
  334. </para>
  335. </listitem>
  336. </itemizedlist>
  337. </listitem>
  338. <listitem>
  339. <para>
  340. <methodname>replies()</methodname> returns the 20 most recent @replies (status
  341. updates prefixed with @username) for the authenticating user.
  342. </para>
  343. <example id="zend.service.twitter.status.replies">
  344. <title>Showing user replies</title>
  345. <programlisting language="php"><![CDATA[
  346. $twitter = new Zend_Service_Twitter(array(
  347. 'username' => 'johndoe',
  348. 'accessToken' => $token
  349. ));
  350. $response = $twitter->status->replies();
  351. ]]></programlisting>
  352. </example>
  353. <para>
  354. The <methodname>replies()</methodname> method accepts an array of optional
  355. parameters to modify the query.
  356. </para>
  357. <itemizedlist>
  358. <listitem>
  359. <para>
  360. <code>since</code> narrows the returned results to just those statuses
  361. created after the specified date/time (up to 24 hours old).
  362. </para>
  363. </listitem>
  364. <listitem>
  365. <para>
  366. <code>page</code> specifies which page you want to return.
  367. </para>
  368. </listitem>
  369. <listitem>
  370. <para>
  371. <code>since_id</code> returns only statuses with an ID greater than
  372. (that is, more recent than) the specified ID.
  373. </para>
  374. </listitem>
  375. </itemizedlist>
  376. </listitem>
  377. <listitem>
  378. <para>
  379. <methodname>destroy()</methodname> destroys the status specified by the
  380. required <code>id</code> parameter.
  381. </para>
  382. <example id="zend.service.twitter.status.destroy">
  383. <title>Deleting user status</title>
  384. <programlisting language="php"><![CDATA[
  385. $twitter = new Zend_Service_Twitter(array(
  386. 'username' => 'johndoe',
  387. 'accessToken' => $token
  388. ));
  389. $response = $twitter->status->destroy(12345);
  390. ]]></programlisting>
  391. </example>
  392. </listitem>
  393. </itemizedlist>
  394. </sect2>
  395. <sect2 id="zend.service.twitter.user">
  396. <title>User Methods</title>
  397. <itemizedlist>
  398. <listitem>
  399. <para>
  400. <methodname>friends()</methodname>r eturns up to 100 of the authenticating
  401. user's friends who have most recently updated, each with current status inline.
  402. </para>
  403. <example id="zend.service.twitter.user.friends">
  404. <title>Retrieving user friends</title>
  405. <programlisting language="php"><![CDATA[
  406. $twitter = new Zend_Service_Twitter(array(
  407. 'username' => 'johndoe',
  408. 'accessToken' => $token
  409. ));
  410. $response = $twitter->user->friends();
  411. ]]></programlisting>
  412. </example>
  413. <para>
  414. The <methodname>friends()</methodname> method accepts an array of optional
  415. parameters to modify the query.
  416. </para>
  417. <itemizedlist>
  418. <listitem>
  419. <para>
  420. <code>id</code> specifies the ID or screen name of the user for whom to
  421. return a list of friends.
  422. </para>
  423. </listitem>
  424. <listitem>
  425. <para>
  426. <code>since</code> narrows the returned results to just those statuses
  427. created after the specified date/time (up to 24 hours old).
  428. </para>
  429. </listitem>
  430. <listitem>
  431. <para>
  432. <code>page</code> specifies which page you want to return.
  433. </para>
  434. </listitem>
  435. </itemizedlist>
  436. </listitem>
  437. <listitem>
  438. <para>
  439. <methodname>followers()</methodname> returns the authenticating user's
  440. followers, each with current status inline.
  441. </para>
  442. <example id="zend.service.twitter.user.followers">
  443. <title>Retrieving user followers</title>
  444. <programlisting language="php"><![CDATA[
  445. $twitter = new Zend_Service_Twitter(array(
  446. 'username' => 'johndoe',
  447. 'accessToken' => $token
  448. ));
  449. $response = $twitter->user->followers();
  450. ]]></programlisting>
  451. </example>
  452. <para>
  453. The <methodname>followers()</methodname> method accepts an array of optional
  454. parameters to modify the query.
  455. </para>
  456. <itemizedlist>
  457. <listitem>
  458. <para>
  459. <code>id</code> specifies the ID or screen name of the user for whom to
  460. return a list of followers.
  461. </para>
  462. </listitem>
  463. <listitem>
  464. <para>
  465. <code>page</code> specifies which page you want to return.
  466. </para>
  467. </listitem>
  468. </itemizedlist>
  469. </listitem>
  470. <listitem>
  471. <para>
  472. <methodname>show()</methodname> returns extended information of a given user,
  473. specified by ID or screen name as per the required <code>id</code>
  474. parameter below.
  475. </para>
  476. <example id="zend.service.twitter.user.show">
  477. <title>Showing user informations</title>
  478. <programlisting language="php"><![CDATA[
  479. $twitter = new Zend_Service_Twitter(array(
  480. 'username' => 'johndoe',
  481. 'accessToken' => $token
  482. ));
  483. $response = $twitter->user->show('myfriend');
  484. ]]></programlisting>
  485. </example>
  486. </listitem>
  487. </itemizedlist>
  488. </sect2>
  489. <sect2 id="zend.service.twitter.directmessage">
  490. <title>Direct Message Methods</title>
  491. <itemizedlist>
  492. <listitem>
  493. <para>
  494. <methodname>messages()</methodname> returns a list of the 20 most recent direct
  495. messages sent to the authenticating user.
  496. </para>
  497. <example id="zend.service.twitter.directmessage.messages">
  498. <title>Retrieving recent direct messages received</title>
  499. <programlisting language="php"><![CDATA[
  500. $twitter = new Zend_Service_Twitter(array(
  501. 'username' => 'johndoe',
  502. 'accessToken' => $token
  503. ));
  504. $response = $twitter->directMessage->messages();
  505. ]]></programlisting>
  506. </example>
  507. <para>
  508. The <methodname>message()</methodname> method accepts an array of optional
  509. parameters to modify the query.
  510. </para>
  511. <itemizedlist>
  512. <listitem>
  513. <para>
  514. <code>since_id</code> returns only direct messages with an ID greater
  515. than (that is, more recent than) the specified ID.
  516. </para>
  517. </listitem>
  518. <listitem>
  519. <para>
  520. <code>since</code> narrows the returned results to just those statuses
  521. created after the specified date/time (up to 24 hours old).
  522. </para>
  523. </listitem>
  524. <listitem>
  525. <para>
  526. <code>page</code> specifies which page you want to return.
  527. </para>
  528. </listitem>
  529. </itemizedlist>
  530. </listitem>
  531. <listitem>
  532. <para>
  533. <methodname>sent()</methodname> returns a list of the 20 most recent direct
  534. messages sent by the authenticating user.
  535. </para>
  536. <example id="zend.service.twitter.directmessage.sent">
  537. <title>Retrieving recent direct messages sent</title>
  538. <programlisting language="php"><![CDATA[
  539. $twitter = new Zend_Service_Twitter(array(
  540. 'username' => 'johndoe',
  541. 'accessToken' => $token
  542. ));
  543. $response = $twitter->directMessage->sent();
  544. ]]></programlisting>
  545. </example>
  546. <para>
  547. The <methodname>sent()</methodname> method accepts an array of optional
  548. parameters to modify the query.
  549. </para>
  550. <itemizedlist>
  551. <listitem>
  552. <para>
  553. <code>since_id</code> returns only direct messages with an ID greater
  554. than (that is, more recent than) the specified ID.
  555. </para>
  556. </listitem>
  557. <listitem>
  558. <para>
  559. <code>since</code> narrows the returned results to just those statuses
  560. created after the specified date/time (up to 24 hours old).
  561. </para>
  562. </listitem>
  563. <listitem>
  564. <para>
  565. <code>page</code> specifies which page you want to return.
  566. </para>
  567. </listitem>
  568. </itemizedlist>
  569. </listitem>
  570. <listitem>
  571. <para>
  572. <methodname>new()</methodname> sends a new direct message to the specified user
  573. from the authenticating user. Requires both the user and text parameters below.
  574. </para>
  575. <example id="zend.service.twitter.directmessage.new">
  576. <title>Sending direct message</title>
  577. <programlisting language="php"><![CDATA[
  578. $twitter = new Zend_Service_Twitter(array(
  579. 'username' => 'johndoe',
  580. 'accessToken' => $token
  581. ));
  582. $response = $twitter->directMessage->new('myfriend', 'mymessage');
  583. ]]></programlisting>
  584. </example>
  585. </listitem>
  586. <listitem>
  587. <para>
  588. <methodname>destroy()</methodname> destroys the direct message specified in the
  589. required <code>id</code> parameter. The authenticating user must be the
  590. recipient of the specified direct message.
  591. </para>
  592. <example id="zend.service.twitter.directmessage.destroy">
  593. <title>Deleting direct message</title>
  594. <programlisting language="php"><![CDATA[
  595. $twitter = new Zend_Service_Twitter(array(
  596. 'username' => 'johndoe',
  597. 'accessToken' => $token
  598. ));
  599. $response = $twitter->directMessage->destroy(123548);
  600. ]]></programlisting>
  601. </example>
  602. </listitem>
  603. </itemizedlist>
  604. </sect2>
  605. <sect2 id="zend.service.twitter.friendship">
  606. <title>Friendship Methods</title>
  607. <itemizedlist>
  608. <listitem>
  609. <para>
  610. <methodname>create()</methodname> befriends the user specified in the
  611. <code>id</code> parameter with the authenticating user.
  612. </para>
  613. <example id="zend.service.twitter.friendship.create">
  614. <title>Creating friend</title>
  615. <programlisting language="php"><![CDATA[
  616. $twitter = new Zend_Service_Twitter(array(
  617. 'username' => 'johndoe',
  618. 'accessToken' => $token
  619. ));
  620. $response = $twitter->friendship->create('mynewfriend');
  621. ]]></programlisting>
  622. </example>
  623. </listitem>
  624. <listitem>
  625. <para>
  626. <methodname>destroy()</methodname> discontinues friendship with the user
  627. specified in the <code>id</code> parameter and the authenticating user.
  628. </para>
  629. <example id="zend.service.twitter.friendship.destroy">
  630. <title>Deleting friend</title>
  631. <programlisting language="php"><![CDATA[
  632. $twitter = new Zend_Service_Twitter(array(
  633. 'username' => 'johndoe',
  634. 'accessToken' => $token
  635. ));
  636. $response = $twitter->friendship->destroy('myoldfriend');
  637. ]]></programlisting>
  638. </example>
  639. </listitem>
  640. <listitem>
  641. <para>
  642. <methodname>exists()</methodname> tests if a friendship exists between the
  643. user specified in the <code>id</code> parameter and the authenticating user.
  644. </para>
  645. <example id="zend.service.twitter.friendship.exists">
  646. <title>Checking friend existence</title>
  647. <programlisting language="php"><![CDATA[
  648. $twitter = new Zend_Service_Twitter(array(
  649. 'username' => 'johndoe',
  650. 'accessToken' => $token
  651. ));
  652. $response = $twitter->friendship->exists('myfriend');
  653. ]]></programlisting>
  654. </example>
  655. </listitem>
  656. </itemizedlist>
  657. </sect2>
  658. <sect2 id="zend.service.twitter.favorite">
  659. <title>Favorite Methods</title>
  660. <itemizedlist>
  661. <listitem>
  662. <para>
  663. <methodname>favorites()</methodname> returns the 20 most recent favorite
  664. statuses for the authenticating user or user specified by the
  665. <code>id</code> parameter.
  666. </para>
  667. <example id="zend.service.twitter.favorite.favorites">
  668. <title>Retrieving favorites</title>
  669. <programlisting language="php"><![CDATA[
  670. $twitter = new Zend_Service_Twitter(array(
  671. 'username' => 'johndoe',
  672. 'accessToken' => $token
  673. ));
  674. $response = $twitter->favorite->favorites();
  675. ]]></programlisting>
  676. </example>
  677. <para>
  678. The <methodname>favorites()</methodname> method accepts an array of optional
  679. parameters to modify the query.
  680. </para>
  681. <itemizedlist>
  682. <listitem>
  683. <para>
  684. <code>id</code> specifies the ID or screen name of the user for whom to
  685. request a list of favorite statuses.
  686. </para>
  687. </listitem>
  688. <listitem>
  689. <para>
  690. <code>page</code> specifies which page you want to return.
  691. </para>
  692. </listitem>
  693. </itemizedlist>
  694. </listitem>
  695. <listitem>
  696. <para>
  697. <methodname>create()</methodname> favorites the status specified in the
  698. <code>id</code> parameter as the authenticating user.
  699. </para>
  700. <example id="zend.service.twitter.favorite.create">
  701. <title>Creating favorites</title>
  702. <programlisting language="php"><![CDATA[
  703. $twitter = new Zend_Service_Twitter(array(
  704. 'username' => 'johndoe',
  705. 'accessToken' => $token
  706. ));
  707. $response = $twitter->favorite->create(12351);
  708. ]]></programlisting>
  709. </example>
  710. </listitem>
  711. <listitem>
  712. <para>
  713. <methodname>destroy()</methodname> un-favorites the status specified in the
  714. <code>id</code> parameter as the authenticating user.
  715. </para>
  716. <example id="zend.service.twitter.favorite.destroy">
  717. <title>Deleting favorites</title>
  718. <programlisting language="php"><![CDATA[
  719. $twitter = new Zend_Service_Twitter(array(
  720. 'username' => 'johndoe',
  721. 'accessToken' => $token
  722. ));
  723. $response = $twitter->favorite->destroy(12351);
  724. ]]></programlisting>
  725. </example>
  726. </listitem>
  727. </itemizedlist>
  728. </sect2>
  729. <sect2 id="zend.service.twitter.block">
  730. <title>Block Methods</title>
  731. <itemizedlist>
  732. <listitem>
  733. <para>
  734. <methodname>exists()</methodname> checks if the authenticating user is blocking
  735. a target user and can optionally return the blocked user's object if a
  736. block does exists.
  737. </para>
  738. <example id="zend.service.twitter.block.exists">
  739. <title>Checking if block exists</title>
  740. <programlisting language="php"><![CDATA[
  741. $twitter = new Zend_Service_Twitter(array(
  742. 'username' => 'johndoe',
  743. 'accessToken' => $token
  744. ));
  745. // returns true or false
  746. $response = $twitter->block->exists('blockeduser');
  747. // returns the blocked user's info if the user is blocked
  748. $response2 = $twitter->block->exists('blockeduser', true);
  749. ]]></programlisting>
  750. </example>
  751. <para>
  752. The <methodname>favorites()</methodname> method accepts a second
  753. optional parameter.
  754. </para>
  755. <itemizedlist>
  756. <listitem>
  757. <para>
  758. <code>returnResult</code> specifies whether or not return the user
  759. object instead of just <constant>TRUE</constant> or
  760. <constant>FALSE</constant>.
  761. </para>
  762. </listitem>
  763. </itemizedlist>
  764. </listitem>
  765. <listitem>
  766. <para>
  767. <methodname>create()</methodname> blocks the user specified in the
  768. <code>id</code> parameter as the authenticating user and destroys a friendship
  769. to the blocked user if one exists. Returns the blocked user in the requested
  770. format when successful.
  771. </para>
  772. <example id="zend.service.twitter.block.create">
  773. <title>Blocking a user</title>
  774. <programlisting language="php"><![CDATA[
  775. $twitter = new Zend_Service_Twitter(array(
  776. 'username' => 'johndoe',
  777. 'accessToken' => $token
  778. ));
  779. $response = $twitter->block->create('usertoblock);
  780. ]]></programlisting>
  781. </example>
  782. </listitem>
  783. <listitem>
  784. <para>
  785. <methodname>destroy()</methodname> un-blocks the user specified in the
  786. <code>id</code> parameter for the authenticating user. Returns the un-blocked
  787. user in the requested format when successful.
  788. </para>
  789. <example id="zend.service.twitter.block.destroy">
  790. <title>Removing a block</title>
  791. <programlisting language="php"><![CDATA[
  792. $twitter = new Zend_Service_Twitter(array(
  793. 'username' => 'johndoe',
  794. 'accessToken' => $token
  795. ));
  796. $response = $twitter->block->destroy('blockeduser');
  797. ]]></programlisting>
  798. </example>
  799. </listitem>
  800. <listitem>
  801. <para>
  802. <methodname>blocking()</methodname> returns an array of user objects that the
  803. authenticating user is blocking.
  804. </para>
  805. <example id="zend.service.twitter.block.blocking">
  806. <title>Who are you blocking</title>
  807. <programlisting language="php"><![CDATA[
  808. $twitter = new Zend_Service_Twitter(array(
  809. 'username' => 'johndoe',
  810. 'accessToken' => $token
  811. ));
  812. // return the full user list from the first page
  813. $response = $twitter->block->blocking();
  814. // return an array of numeric user IDs from the second page
  815. $response2 = $twitter->block->blocking(2, true);
  816. ]]></programlisting>
  817. </example>
  818. <para>
  819. The <methodname>favorites()</methodname> method accepts two optional parameters.
  820. </para>
  821. <itemizedlist>
  822. <listitem>
  823. <para>
  824. <code>page</code> specifies which page ou want to return. A single page
  825. contains 20 IDs.
  826. </para>
  827. </listitem>
  828. <listitem>
  829. <para>
  830. <code>returnUserIds</code> specifies whether to return an array of
  831. numeric user IDs the authenticating user is blocking instead of an
  832. array of user objects.
  833. </para>
  834. </listitem>
  835. </itemizedlist>
  836. </listitem>
  837. </itemizedlist>
  838. </sect2>
  839. <xi:include href="Zend_Service_Twitter_Search.xml" />
  840. </sect1>
  841. <!--
  842. vim:se ts=4 sw=4 et:
  843. -->