Service/Twitter.php
LICENSE
This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Service
- Subpackage
- Version
- $Id: Twitter.php 25288 2013-03-13 13:36:39Z matthew $
\Zend_Service_Twitter
- Category
- Zend
- Copyright
- Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Constants

STATUS_MAX_CHARACTERS
= 246
The limit is applied to a html encoded UTF-8 string (i.e. entities are counted in the limit which may appear unusual but is a security measure).
This should be reviewed in the future...
Properties


string $dateFormat = 'D, d M Y H:i:s T'
'D, d M Y H:i:s T'
Details- Type
- string


array $methodTypes = array('account', 'application', 'blocks', 'directmessages', 'favorites', 'friendships', 'search', 'statuses', 'users')
array('account', 'application', 'blocks', 'directmessages', 'favorites', 'friendships', 'search', 'statuses', 'users')
Details- Type
- array
Methods


__call(string $method, array $params) : mixed
Method overloading
Name | Type | Description |
---|---|---|
$method | string | |
$params | array |
Type | Description |
---|---|
mixed |
Exception | Description |
---|---|
\Exception\BadMethodCallException | if unable to find method |


__construct(null | array | \Zend_Config $options = null, null | \Zend_Oauth_Consumer $consumer = null, null | \Zend_Http_Client $httpClient = null) : void
Constructor
Name | Type | Description |
---|---|---|
$options | null | array | \Zend_Config | |
$consumer | null | \Zend_Oauth_Consumer | |
$httpClient | null | \Zend_Http_Client |


__get(string $type) : \Twitter
Proxy service methods
Name | Type | Description |
---|---|---|
$type | string |
Type | Description |
---|---|
Exception | Description |
---|---|
\Exception\DomainException | If method not in method types list |


accountVerifyCredentials() : \Zend_Service_Twitter_Response
Verify Account Credentials
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


applicationRateLimitStatus() : \Zend_Service_Twitter_Response
Returns the number of api requests you have left per hour.
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |
- Todo
- Have a separate payload object to represent rate limits


blocksCreate(integer | string $id) : \Zend_Service_Twitter_Response
Blocks the user specified in the ID parameter as the authenticating user.
Destroys a friendship to the blocked user if it exists.
Name | Type | Description |
---|---|---|
$id | integer | string | The ID or screen name of a user to block. |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Exception\DomainException | if unable to decode JSON payload |


blocksDestroy(integer | string $id) : \Zend_Service_Twitter_Response
Un-blocks the user specified in the ID parameter for the authenticating user
Name | Type | Description |
---|---|---|
$id | integer | string | The ID or screen_name of the user to un-block. |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Exception\DomainException | if unable to decode JSON payload |


blocksIds(integer $cursor = -1) : \Zend_Service_Twitter_Response
Returns an array of user ids that the authenticating user is blocking
Name | Type | Description |
---|---|---|
$cursor | integer | Optional. Specifies the cursor position at which to begin listing ids; defaults to first "page" of results. |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Exception\DomainException | if unable to decode JSON payload |


blocksList(integer $cursor = -1) : \Zend_Service_Twitter_Response
Returns an array of user objects that the authenticating user is blocking
Name | Type | Description |
---|---|---|
$cursor | integer | Optional. Specifies the cursor position at which to begin listing ids; defaults to first "page" of results. |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Exception\DomainException | if unable to decode JSON payload |


createUserParameter(int | string $id, array $params) : array
Create a parameter representing the user
Determines if $id is an integer, and, if so, sets the "user_id" parameter. If not, assumes the $id is the "screen_name".
Name | Type | Description |
---|---|---|
$id | int | string | |
$params | array |
Type | Description |
---|---|
array |


directMessagesDestroy(int $id) : \Zend_Service_Twitter_Response
Destroy a direct message
Name | Type | Description |
---|---|---|
$id | int | ID of message to destroy |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


directMessagesMessages(array $options = array()) : \Zend_Service_Twitter_Response
Retrieve direct messages for the current user
$options may include one or more of the following keys - count: return page X of results - since_id: return statuses only greater than the one specified - max_id: return statuses with an ID less than (older than) or equal to that specified - include_entities: setting to false will disable embedded entities - skip_status:setting to true, "t", or 1 will omit the status in returned users
Name | Type | Description |
---|---|---|
$options | array |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


directMessagesNew(int | string $user, string $text) : \Zend_Service_Twitter_Response
Send a direct message to a user
Name | Type | Description |
---|---|---|
$user | int | string | User to whom to send message |
$text | string | Message to send to user |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Exception\InvalidArgumentException | if message is empty |
\Exception\OutOfRangeException | if message is too long |
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


directMessagesSent(array $options = array()) : \Zend_Service_Twitter_Response
Retrieve list of direct messages sent by current user
$options may include one or more of the following keys - count: return page X of results - page: return starting at page - since_id: return statuses only greater than the one specified - max_id: return statuses with an ID less than (older than) or equal to that specified - include_entities: setting to false will disable embedded entities
Name | Type | Description |
---|---|---|
$options | array |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


favoritesCreate(int $id) : \Zend_Service_Twitter_Response
Mark a status as a favorite
Name | Type | Description |
---|---|---|
$id | int | Status ID you want to mark as a favorite |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


favoritesDestroy(int $id) : \Zend_Service_Twitter_Response
Remove a favorite
Name | Type | Description |
---|---|---|
$id | int | Status ID you want to de-list as a favorite |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


favoritesList( $options = array()) : \Zend_Service_Twitter_Response
Fetch favorites
$options may contain one or more of the following: - user_id: Id of a user for whom to fetch favorites - screen_name: Screen name of a user for whom to fetch favorites - count: number of tweets to attempt to retrieve, up to 200 - since_id: return results only after the specified tweet id - max_id: return results with an ID less than (older than) or equal to the specified ID - include_entities: when set to false, entities member will be omitted
Name | Type | Description |
---|---|---|
$options |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


friendshipsCreate(int | string $id, array $params = array()) : \Zend_Service_Twitter_Response
Create friendship
Name | Type | Description |
---|---|---|
$id | int | string | User ID or name of new friend |
$params | array | Additional parameters to pass |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


friendshipsDestroy(int | string $id) : \Zend_Service_Twitter_Response
Destroy friendship
Name | Type | Description |
---|---|---|
$id | int | string | User ID or name of friend to remove |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


get(string $path, array $query = array()) : \Zend_Http_Response
Performs an HTTP GET request to the $path.
Name | Type | Description |
---|---|---|
$path | string | |
$query | array | Array of GET parameters |
Type | Description |
---|---|
\Zend_Http_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |


getHttpClient() : \Zend_Http_Client
Get the HTTP client
Lazy loads one if none present
Type | Description |
---|---|
\Zend_Http_Client |


init() : void
Initialize HTTP authentication
Exception | Description |
---|---|
\Exception\DomainException | if unauthorised |


performPost(mixed $method, mixed $data, $client) : \Zend_Http_Response
Perform a POST or PUT
Performs a POST or PUT request. Any data provided is set in the HTTP client. String data is pushed in as raw POST data; array or object data is pushed in as POST parameters.
Name | Type | Description |
---|---|---|
$method | mixed | |
$data | mixed | |
$client |
Type | Description |
---|---|
\Zend_Http_Response |


post(string $path, mixed $data = null) : \Zend_Http_Response
Performs an HTTP POST request to $path.
Name | Type | Description |
---|---|---|
$path | string | |
$data | mixed | Raw data to send |
Type | Description |
---|---|
\Zend_Http_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |


prepare(string $path, \Zend_Http_Client $client) : void
Call a remote REST web service URI
Name | Type | Description |
---|---|---|
$path | string | The path to append to the URI |
$client | \Zend_Http_Client |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |


searchTweets(string $query, array $options = array()) : \Zend_Service_Twitter_Response
Search tweets
$options may include any of the following: - geocode: a string of the form "latitude, longitude, radius" - lang: restrict tweets to the two-letter language code - locale: query is in the given two-letter language code - result_type: what type of results to receive: mixed, recent, or popular - count: number of tweets to return per page; up to 100 - until: return tweets generated before the given date - since_id: return resutls with an ID greater than (more recent than) the given ID - max_id: return results with an ID less than (older than) the given ID - include_entities: whether or not to include embedded entities
Name | Type | Description |
---|---|---|
$query | string | |
$options | array |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


setHttpClient(\Zend_Http_Client $client) : \Zend_Service_Twitter
Set HTTP client
Name | Type | Description |
---|---|---|
$client | \Zend_Http_Client |
Type | Description |
---|---|
\Zend_Service_Twitter |
- Fluent
- This method is part of a fluent interface and will return the same instance


setUsername(string $value) : \Zend_Service_Twitter
Set username
Name | Type | Description |
---|---|---|
$value | string |
Type | Description |
---|---|
\Zend_Service_Twitter |
- Fluent
- This method is part of a fluent interface and will return the same instance


statusesDestroy(int $id) : \Zend_Service_Twitter_Response
Destroy a status message
Name | Type | Description |
---|---|---|
$id | int | ID of status to destroy |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


statusesHomeTimeline( $options = array()) : \Zend_Service_Twitter_Response
Friend Timeline Status
$options may include one or more of the following keys - count: number of tweets to attempt to retrieve, up to 200 - since_id: return results only after the specified tweet id - max_id: return results with an ID less than (older than) or equal to the specified ID - trim_user: when set to true, "t", or 1, user object in tweets will include only author's ID. - contributor_details: when set to true, includes screen_name of each contributor - include_entities: when set to false, entities member will be omitted - exclude_replies: when set to true, will strip replies appearing in the timeline
Name | Type | Description |
---|---|---|
$options |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


statusesMentionsTimeline(array $options = array()) : \Zend_Service_Twitter_Response
Get status replies
$options may include one or more of the following keys - count: number of tweets to attempt to retrieve, up to 200 - since_id: return results only after the specified tweet id - max_id: return results with an ID less than (older than) or equal to the specified ID - trim_user: when set to true, "t", or 1, user object in tweets will include only author's ID. - contributor_details: when set to true, includes screen_name of each contributor - include_entities: when set to false, entities member will be omitted
Name | Type | Description |
---|---|---|
$options | array |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


statusesSample() : \Zend_Service_Twitter_Response
Public Timeline status
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


statusesShow(int $id) : \Zend_Service_Twitter_Response
Show a single status
Name | Type | Description |
---|---|---|
$id | int | Id of status to show |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


statusesUpdate(string $status, null | int $inReplyToStatusId = null) : \Zend_Service_Twitter_Response
Update user's current status
Name | Type | Description |
---|---|---|
$status | string | |
$inReplyToStatusId | null | int |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\OutOfRangeException | if message is too long |
\Exception\InvalidArgumentException | if message is empty |
\Exception\DomainException | if unable to decode JSON payload |
- Todo
- Support additional parameters supported by statuses/update endpoint


statusesUserTimeline( $options = array()) : \Zend_Service_Twitter_Response
User Timeline status
$options may include one or more of the following keys - user_id: Id of a user for whom to fetch favorites - screen_name: Screen name of a user for whom to fetch favorites - count: number of tweets to attempt to retrieve, up to 200 - since_id: return results only after the specified tweet id - max_id: return results with an ID less than (older than) or equal to the specified ID - trim_user: when set to true, "t", or 1, user object in tweets will include only author's ID. - exclude_replies: when set to true, will strip replies appearing in the timeline - contributor_details: when set to true, includes screen_name of each contributor - include_rts: when set to false, will strip native retweets
Name | Type | Description |
---|---|---|
$options |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


usersSearch(string $query, array $options = array()) : \Zend_Service_Twitter_Response
Search users
$options may include any of the following: - page: the page of results to retrieve - count: the number of users to retrieve per page; max is 20 - include_entities: if set to boolean true, include embedded entities
Name | Type | Description |
---|---|---|
$query | string | |
$options | array |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


usersShow(int | string $id) : \Zend_Service_Twitter_Response
Show extended information on a user
Name | Type | Description |
---|---|---|
$id | int | string | User ID or name |
Type | Description |
---|---|
\Zend_Service_Twitter_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Exception\DomainException | if unable to decode JSON payload |


validInteger( $int) : integer
Protected function to validate that the integer is valid or return a 0
Name | Type | Description |
---|---|---|
$int |
Type | Description |
---|---|
integer |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |