Zend_Service_TwitterIntroductionZend_Service_Twitter provides a client for the » Twitter REST API. Zend_Service_Twitter allows you to query the public timeline. If you provide a username and OAuth details for Twitter, it will allow you to get and update your status, reply to friends, direct message friends, mark tweets as favorite, and much more. Zend_Service_Twitter implements a REST service, and all methods return an instance of Zend_Rest_Client_Result. Zend_Service_Twitter is broken up into subsections so you can easily identify which type of call is being requested.
AuthenticationWith the exception of fetching the public timeline, Zend_Service_Twitter requires authentication as a valid user. This is achieved using the OAuth authentication protocol. OAuth is the only supported authentication mode for Twitter as of August 2010. The OAuth implementation used by Zend_Service_Twitter is Zend_Oauth. Example #1 Creating the Twitter Class Zend_Service_Twitter must authorize itself, on behalf of a user, before use with the Twitter API (except for public timeline). This must be accomplished using OAuth since Twitter has disabled it's basic HTTP authentication as of August 2010. There are two options to establishing authorization. The first is to implement the workflow of Zend_Oauth via Zend_Service_Twitter which proxies to an internal Zend_Oauth_Consumer object. Please refer to the Zend_Oauth documentation for a full example of this workflow - you can call all documented Zend_Oauth_Consumer methods on Zend_Service_Twitter including constructor options. You may also use Zend_Oauth directly and only pass the resulting access token into Zend_Service_Twitter. This is the normal workflow once you have established a reusable access token for a particular Twitter user. The resulting OAuth access token should be stored to a database for future use (otherwise you will need to authorize for every new instance of Zend_Service_Twitter). Bear in mind that authorization via OAuth results in your user being redirected to Twitter to give their consent to the requested authorization (this is not repeated for stored access tokens). This will require additional work (i.e. redirecting users and hosting a callback URL) over the previous HTTP authentication mechanism where a user just needed to allow applications to store their username and password. The following example demonstrates setting up Zend_Service_Twitter which is given an already established OAuth access token. Please refer to the Zend_Oauth documentation to understand the workflow involved. The access token is a serializable object, so you may store the serialized object to a database, and unserialize it at retrieval time before passing the objects into Zend_Service_Twitter. The Zend_Oauth documentation demonstrates the workflow and objects involved.
Account Methods
Status Methods
User Methods
Direct Message Methods
Friendship Methods
Favorite Methods
Block Methods
Zend_Service_Twitter_SearchIntroductionZend_Service_Twitter_Search provides a client for the » Twitter Search API. The Twitter Search service is use to search Twitter. Currently, it only returns data in Atom or JSON format, but a full REST service is in the future, which will support XML responses. Twitter TrendsReturns the top ten queries that are currently trending on Twitter. The response includes the time of the request, the name of each trending topic, and the url to the Twitter Search results page for that topic. Currently the search API for trends only supports a JSON return so the function returns an array.
The return array has two values in it:
Searching TwitterUsing the search method returns tweets that match a specific query. There are a number of » Search Operators that you can use to query with. The search method can accept six different optional URL parameters passed in as an array:
Example #29 JSON Search Example The following code sample will return an array with the search results.
Example #30 ATOM Search Example The following code sample will return a Zend_Feed_Atom object.
Zend-specific Accessor MethodsWhile the Twitter Search API only specifies two methods, Zend_Service_Twitter_Search has additional methods that may be used for retrieving and modifying internal properties.
|
|