1 <?xml version="1.0" encoding="utf-8"?>
2 <!-- EN-Revision: 21829 -->
4 <sect1 id="zend.service.twitter" xmlns:xi="http://www.w3.org/2001/XInclude">
5 <title>Zend_Service_Twitter</title>
6 <sect2 id="zend.service.twitter.introduction">
7 <title>Introduction</title>
9 <classname>Zend_Service_Twitter</classname> fournit un client pour
10 <ulink url="http://apiwiki.twitter.com/Twitter-API-Documentation">l'<acronym>API</acronym>
11 <acronym>REST</acronym> de Twitter</ulink>.
12 <classname>Zend_Service_Twitter</classname> vous permet d'interroger les fils (timeline) publics.
13 En fournissant un nom d'utilisateur et un mot de passe pour Twitter, il vous permettra également
14 de récupérer et mettre à jour votre statut, de répondre à des amis, de leur envoyer des messages
15 directs, de marquer des tweets comme favoris et beaucoup d'autres choses.
18 <classname>Zend_Service_Twitter</classname> implémente un service <acronym>REST</acronym>,
19 et toutes ses méthodes retournes une instance de <classname>Zend_Rest_Client_Result</classname>.
22 <classname>Zend_Service_Twitter</classname> et subdivisé en sections, ainsi vous pouvez
23 facilement identifier le type d'appel qui est demandé.
28 <code>account</code> s'assure que vos données de compte sont valides, vérifie
29 votre taux limite pour l'<acronym>API</acronym> et termine la session courante
30 pour l'utilisateur authentifié.
35 <code>status</code> retourne les fils publics et ceux de
36 l'utilisateur et montre, met à jour, détruit et retourne des réponses
37 pour l'utilisateur authentifié.
42 <code>user</code> récupère les amis et 'followers' de l'utilisateur
43 authentifié et retourne de plus amples informations sur l'utilisateur
49 <code>directMessage</code> récupère les messages directs reçus par l'utilisateur
50 authentifié, supprime les messages directs et permet également d'envoyer des
56 <code>friendship</code> crée et supprime des amitiés pour l'utilisateur
62 <code>favorite</code> liste, crée et détruit des tweets favoris.
67 <code>block</code> bloque et débloque des utilisateurs qui vous suivent.
72 <sect2 id="zend.service.twitter.authentication">
73 <title>Authentification</title>
75 A l'exception de la récupération du fil public, <classname>Zend_Service_Twitter</classname>
76 nécessite une authentification pour fonctionner.
77 Twitter utilise l'<ulink url="http://en.wikipedia.org/wiki/Basic_authentication_scheme">Authentification HTTP basique</ulink>.
78 Vous pouvez lui passer votre nom d'utilisateur ou votre email utilisé pour l'enregistrement de votre compte
79 ainsi que votre mot de passe pour vous connecter à Twitter.
81 <example id="zend.service.twitter.authentication.example">
82 <title>Créer la classe Twitter</title>
84 L'exemple de code suivant décrit comment créer le service Twitter, lui passer
85 vos nom d'utilisateur et mot de passe et vérifier qu'ils sont corrects.
87 <programlisting language="php"><![CDATA[
88 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
89 // vérifie vos données de connexion avec Twitter
90 $response = $twitter->account->verifyCredentials();
93 Vous pouvez également passer un tableau qui contient le nom d'utilisateur
94 et le mot de passe en tant que premier argument
96 <programlisting language="php"><![CDATA[
97 $userInfo = array('username' => 'foo', 'password' => 'bar');
98 $twitter = new Zend_Service_Twitter($userInfo);
99 // vérifie vos données de connexion avec Twitter
100 $response = $twitter->account->verifyCredentials();
104 <sect2 id="zend.service.twitter.account">
105 <title>Account Methods</title>
109 <methodname>verifyCredentials()</methodname> tests if supplied user
110 credentials are valid with minimal overhead.
112 <example id="zend.service.twitter.account.verifycredentails">
113 <title>Verifying credentials</title>
114 <programlisting language="php"><![CDATA[
115 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
116 $response = $twitter->account->verifyCredentials();
122 <methodname>endSession()</methodname> signs users out of
123 client-facing applications.
125 <example id="zend.service.twitter.account.endsession">
126 <title>Sessions ending</title>
127 <programlisting language="php"><![CDATA[
128 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
129 $response = $twitter->account->endSession();
135 <methodname>rateLimitStatus()</methodname> returns the remaining number of
136 <acronym>API</acronym> requests available to the authenticating user
137 before the <acronym>API</acronym> limit is reached for the current hour.
139 <example id="zend.service.twitter.account.ratelimitstatus">
140 <title>Rating limit status</title>
141 <programlisting language="php"><![CDATA[
142 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
143 $response = $twitter->account->rateLimitStatus();
149 <sect2 id="zend.service.twitter.status">
150 <title>Status Methods</title>
154 <methodname>publicTimeline()</methodname> returns the 20 most recent statuses
155 from non-protected users with a custom user icon. The public timeline is cached
156 by Twitter for 60 seconds.
158 <example id="zend.service.twitter.status.publictimeline">
159 <title>Retrieving public timeline</title>
160 <programlisting language="php"><![CDATA[
161 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
162 $response = $twitter->status->publicTimeline();
168 <methodname>friendsTimeline()</methodname> returns the 20 most recent statuses
169 posted by the authenticating user and that user's friends.
171 <example id="zend.service.twitter.status.friendstimeline">
172 <title>Retrieving friends timeline</title>
173 <programlisting language="php"><![CDATA[
174 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
175 $response = $twitter->status->friendsTimeline();
179 The <methodname>friendsTimeline()</methodname> method accepts an array of
180 optional parameters to modify the query.
185 <code>since</code> narrows the returned results to just those statuses
186 created after the specified date/time (up to 24 hours old).
191 <code>page</code> specifies which page you want to return.
198 <methodname>userTimeline()</methodname> returns the 20 most recent statuses
199 posted from the authenticating user.
201 <example id="zend.service.twitter.status.usertimeline">
202 <title>Retrieving user timeline</title>
203 <programlisting language="php"><![CDATA[
204 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
205 $response = $twitter->status->userTimeline();
209 The <methodname>userTimeline()</methodname> method accepts an array of optional
210 parameters to modify the query.
215 <code>id</code> specifies the ID or screen name of the user for whom to
216 return the friends_timeline.
221 <code>since</code> narrows the returned results to just those statuses
222 created after the specified date/time (up to 24 hours old).
227 <code>page</code> specifies which page you want to return.
232 <code>count</code> specifies the number of statuses to retrieve.
233 May not be greater than 200.
240 <methodname>show()</methodname> returns a single status, specified by the
241 <code>id</code> parameter below. The status' author will be returned inline.
243 <example id="zend.service.twitter.status.show">
244 <title>Showing user status</title>
245 <programlisting language="php"><![CDATA[
246 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
247 $response = $twitter->status->show(1234);
253 <methodname>update()</methodname> updates the authenticating user's status.
254 This method requires that you pass in the status update that you want to post
257 <example id="zend.service.twitter.status.update">
258 <title>Updating user status</title>
259 <programlisting language="php"><![CDATA[
260 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
261 $response = $twitter->status->update('My Great Tweet');
265 The <methodname>update()</methodname> method accepts a second additional
271 <code>in_reply_to_status_id</code> specifies the ID of an existing
272 status that the status to be posted is in reply to.
279 <methodname>replies()</methodname> returns the 20 most recent @replies (status
280 updates prefixed with @username) for the authenticating user.
282 <example id="zend.service.twitter.status.replies">
283 <title>Showing user replies</title>
284 <programlisting language="php"><![CDATA[
285 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
286 $response = $twitter->status->replies();
290 The <methodname>replies()</methodname> method accepts an array of optional
291 parameters to modify the query.
296 <code>since</code> narrows the returned results to just those statuses
297 created after the specified date/time (up to 24 hours old).
302 <code>page</code> specifies which page you want to return.
307 <code>since_id</code> returns only statuses with an ID greater than
308 (that is, more recent than) the specified ID.
315 <methodname>destroy()</methodname> destroys the status specified by the
316 required <code>id</code> parameter.
318 <example id="zend.service.twitter.status.destroy">
319 <title>Deleting user status</title>
320 <programlisting language="php"><![CDATA[
321 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
322 $response = $twitter->status->destroy(12345);
328 <sect2 id="zend.service.twitter.user">
329 <title>User Methods</title>
333 <methodname>friends()</methodname>r eturns up to 100 of the authenticating
334 user's friends who have most recently updated, each with current status inline.
336 <example id="zend.service.twitter.user.friends">
337 <title>Retrieving user friends</title>
338 <programlisting language="php"><![CDATA[
339 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
340 $response = $twitter->user->friends();
344 The <methodname>friends()</methodname> method accepts an array of optional
345 parameters to modify the query.
350 <code>id</code> specifies the ID or screen name of the user for whom to
351 return a list of friends.
356 <code>since</code> narrows the returned results to just those statuses
357 created after the specified date/time (up to 24 hours old).
362 <code>page</code> specifies which page you want to return.
369 <methodname>followers()</methodname> returns the authenticating user's
370 followers, each with current status inline.
372 <example id="zend.service.twitter.user.followers">
373 <title>Retrieving user followers</title>
374 <programlisting language="php"><![CDATA[
375 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
376 $response = $twitter->user->followers();
380 The <methodname>followers()</methodname> method accepts an array of optional
381 parameters to modify the query.
386 <code>id</code> specifies the ID or screen name of the user for whom to
387 return a list of followers.
392 <code>page</code> specifies which page you want to return.
399 <methodname>show()</methodname> returns extended information of a given user,
400 specified by ID or screen name as per the required <code>id</code>
403 <example id="zend.service.twitter.user.show">
404 <title>Showing user informations</title>
405 <programlisting language="php"><![CDATA[
406 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
407 $response = $twitter->user->show('myfriend');
413 <sect2 id="zend.service.twitter.directmessage">
414 <title>Direct Message Methods</title>
418 <methodname>messages()</methodname> returns a list of the 20 most recent direct
419 messages sent to the authenticating user.
421 <example id="zend.service.twitter.directmessage.messages">
422 <title>Retrieving recent direct messages received</title>
423 <programlisting language="php"><![CDATA[
424 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
425 $response = $twitter->directMessage->messages();
429 The <methodname>message()</methodname> method accepts an array of optional
430 parameters to modify the query.
435 <code>since_id</code> returns only direct messages with an ID greater
436 than (that is, more recent than) the specified ID.
441 <code>since</code> narrows the returned results to just those statuses
442 created after the specified date/time (up to 24 hours old).
447 <code>page</code> specifies which page you want to return.
454 <methodname>sent()</methodname> returns a list of the 20 most recent direct
455 messages sent by the authenticating user.
457 <example id="zend.service.twitter.directmessage.sent">
458 <title>Retrieving recent direct messages sent</title>
459 <programlisting language="php"><![CDATA[
460 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
461 $response = $twitter->directMessage->sent();
465 The <methodname>sent()</methodname> method accepts an array of optional
466 parameters to modify the query.
471 <code>since_id</code> returns only direct messages with an ID greater
472 than (that is, more recent than) the specified ID.
477 <code>since</code> narrows the returned results to just those statuses
478 created after the specified date/time (up to 24 hours old).
483 <code>page</code> specifies which page you want to return.
490 <methodname>new()</methodname> sends a new direct message to the specified user
491 from the authenticating user. Requires both the user and text parameters below.
493 <example id="zend.service.twitter.directmessage.new">
494 <title>Sending direct message</title>
495 <programlisting language="php"><![CDATA[
496 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
497 $response = $twitter->directMessage->new('myfriend', 'mymessage');
503 <methodname>destroy()</methodname> destroys the direct message specified in the
504 required <code>id</code> parameter. The authenticating user must be the
505 recipient of the specified direct message.
507 <example id="zend.service.twitter.directmessage.destroy">
508 <title>Deleting direct message</title>
509 <programlisting language="php"><![CDATA[
510 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
511 $response = $twitter->directMessage->destroy(123548);
517 <sect2 id="zend.service.twitter.friendship">
518 <title>Friendship Methods</title>
522 <methodname>create()</methodname> befriends the user specified in the
523 <code>id</code> parameter with the authenticating user.
525 <example id="zend.service.twitter.friendship.create">
526 <title>Creating friend</title>
527 <programlisting language="php"><![CDATA[
528 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
529 $response = $twitter->friendship->create('mynewfriend');
535 <methodname>destroy()</methodname> discontinues friendship with the user
536 specified in the <code>id</code> parameter and the authenticating user.
538 <example id="zend.service.twitter.friendship.destroy">
539 <title>Deleting friend</title>
540 <programlisting language="php"><![CDATA[
541 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
542 $response = $twitter->friendship->destroy('myoldfriend');
548 <methodname>exists()</methodname> tests if a friendship exists between the
549 user specified in the <code>id</code> parameter and the authenticating user.
551 <example id="zend.service.twitter.friendship.exists">
552 <title>Checking friend existence</title>
553 <programlisting language="php"><![CDATA[
554 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
555 $response = $twitter->friendship->exists('myfriend');
561 <sect2 id="zend.service.twitter.favorite">
562 <title>Favorite Methods</title>
566 <methodname>favorites()</methodname> returns the 20 most recent favorite
567 statuses for the authenticating user or user specified by the
568 <code>id</code> parameter.
570 <example id="zend.service.twitter.favorite.favorites">
571 <title>Retrieving favorites</title>
572 <programlisting language="php"><![CDATA[
573 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
574 $response = $twitter->favorite->favorites();
578 The <methodname>favorites()</methodname> method accepts an array of optional
579 parameters to modify the query.
584 <code>id</code> specifies the ID or screen name of the user for whom to
585 request a list of favorite statuses.
590 <code>page</code> specifies which page you want to return.
597 <methodname>create()</methodname> favorites the status specified in the
598 <code>id</code> parameter as the authenticating user.
600 <example id="zend.service.twitter.favorite.create">
601 <title>Creating favorites</title>
602 <programlisting language="php"><![CDATA[
603 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
604 $response = $twitter->favorite->create(12351);
610 <methodname>destroy()</methodname> un-favorites the status specified in the
611 <code>id</code> parameter as the authenticating user.
613 <example id="zend.service.twitter.favorite.destroy">
614 <title>Deleting favorites</title>
615 <programlisting language="php"><![CDATA[
616 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
617 $response = $twitter->favorite->destroy(12351);
623 <sect2 id="zend.service.twitter.block">
624 <title>Block Methods</title>
628 <methodname>exists()</methodname> checks if the authenticating user is blocking
629 a target user and can optionally return the blocked user's object if a
632 <example id="zend.service.twitter.block.exists">
633 <title>Checking if block exists</title>
634 <programlisting language="php"><![CDATA[
635 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
636 // returns true or false
637 $response = $twitter->block->exists('blockeduser');
638 // returns the blocked user's info if the user is blocked
639 $response2 = $twitter->block->exists('blockeduser', true);
643 The <methodname>favorites()</methodname> method accepts a second
649 <code>returnResult</code> specifies whether or not return the user
650 object instead of just <constant>TRUE</constant> or
651 <constant>FALSE</constant>.
658 <methodname>create()</methodname> blocks the user specified in the
659 <code>id</code> parameter as the authenticating user and destroys a friendship
660 to the blocked user if one exists. Returns the blocked user in the requested
661 format when successful.
663 <example id="zend.service.twitter.block.create">
664 <title>Blocking a user</title>
665 <programlisting language="php"><![CDATA[
666 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
667 $response = $twitter->block->create('usertoblock);
673 <methodname>destroy()</methodname> un-blocks the user specified in the
674 <code>id</code> parameter for the authenticating user. Returns the un-blocked
675 user in the requested format when successful.
677 <example id="zend.service.twitter.block.destroy">
678 <title>Removing a block</title>
679 <programlisting language="php"><![CDATA[
680 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
681 $response = $twitter->block->destroy('blockeduser');
687 <methodname>blocking()</methodname> returns an array of user objects that the
688 authenticating user is blocking.
690 <example id="zend.service.twitter.block.blocking">
691 <title>Who are you blocking</title>
692 <programlisting language="php"><![CDATA[
693 $twitter = new Zend_Service_Twitter('myusername', 'mysecretpassword');
694 // return the full user list from the first page
695 $response = $twitter->block->blocking();
696 // return an array of numeric user IDs from the second page
697 $response2 = $twitter->block->blocking(2, true);
701 The <methodname>favorites()</methodname> method accepts two optional parameters.
706 <code>page</code> specifies which page ou want to return. A single page
712 <code>returnUserIds</code> specifies whether to return an array of
713 numeric user IDs the authenticating user is blocking instead of an
714 array of user objects.
721 <xi:include href="Zend_Service_Twitter_Search.xml">
723 <xi:include href="../../en/module_specs/Zend_Service_Twitter_Search.xml" />