Zend_Service_TwitterIntroductionZend_Service_Twitter provides a client for the » Twitter 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 wraps all web service operations, including OAuth, and all methods return an instance of Zend_Service_Twitter_Response. 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.
If you have registered an application with Twitter, you can also use the access token and access token secret they provide you in order to setup the OAuth consumer. This can be done as follows:
If desired, you can also specify a specific HTTP client instance to use, or provide configuration for the HTTP client. To provide the HTTP client, use the http_client or httpClient key, and provide an instance. To provide HTTP client configuration for setting up an instance, use the key http_client_options or httpClientOptions. As a full example:
Account Methods
Application Methods
Block Methods
Direct Message Methods
Favorites Methods
Friendship Methods
Search Methods
Status Methods
User Methods
|
|