Service/Twitter.php
Zend Framework
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 [email protected] so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Service
- Subpackage
- Version
- $Id: Twitter.php 25267 2013-02-25 17:03:45Z rob $
\Zend_Service_Twitter
- Parent(s)
- \Zend_Rest_Client < \Zend_Service_Abstract
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Constants

STATUS_MAX_CHARACTERS
= 246
246 is the current limit for a status message, 140 characters are displayed initially, with the remainder linked from the web UI or client.
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


array $_data = array()
array()
Details- Type
- array
- Inherited_from
- \Zend_Rest_Client::$$_data


string $_dateFormat = 'D, d M Y H:i:s T'
Date format for 'since' strings
'D, d M Y H:i:s T'
Details- Type
- string


\Zend_Http_Client $_httpClient = null
HTTP Client used to query all web services
Inherited from: \Zend_Service_Abstract::$$_httpClient\Zend_Rest_Client::$$_httpClientnull
Details- Type
- \Zend_Http_Client
- Inherited_from
- \Zend_Service_Abstract::$$_httpClient
- Inherited_from
- \Zend_Rest_Client::$$_httpClient


\Zend_Http_Client $_localHttpClient = null
Local HTTP Client cloned from statically set client
null
Details- Type
- \Zend_Http_Client


array $_methodTypes = array('status', 'user', 'directMessage', 'friendship', 'account', 'favorite', 'block')
Types of API methods
array('status', 'user', 'directMessage', 'friendship', 'account', 'favorite', 'block')
Details- Type
- array


bool $_noReset = false
Flag indicating the Zend_Http_Client is fresh and needs no reset.
<p>true if you do not want a reset. Default false.</p>Inherited from: \Zend_Rest_Client::$$_noResetMust be set explicitly if you want to keep preset parameters.
false
Details- Type
- bool
- Inherited_from
- \Zend_Rest_Client::$$_noReset


\Zend_Oauth_Consumer $_oauthConsumer = null
Zend_Oauth Consumer
null
Details- Type
- \Zend_Oauth_Consumer


\Zend_Uri_Http $_uri = null
null
Details- Type
- \Zend_Uri_Http
- Inherited_from
- \Zend_Rest_Client::$$_uri
Methods


__call(string $method, array $params) : mixed
Method overloading
Allows calling REST actions as object methods; however, you must follow-up by chaining the request with a request to an HTTP request method (post, get, delete, put):
$response = $rest->sayHello('Foo', 'Manchu')->get();
Or use them together, but in sequential calls:
$rest->sayHello('Foo', 'Manchu');
$response = $rest->get();
Name | Type | Description |
---|---|---|
$method | string | |
$params | array |
Type | Description |
---|---|
mixed |
Exception | Description |
---|---|
\Zend_Service_Twitter_Exception | if unable to find method |


__construct(array $options = null, $consumer = null) : void
Constructor
Name | Type | Description |
---|---|---|
$options | array | Optional options array |
$consumer |


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


_get(string $path, array $query = null) : \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 |


_performPost(mixed $method, mixed $data = null) : \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 |
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) : void
Call a remote REST web service URI and return the Zend_Http_Response object
Name | Type | Description |
---|---|---|
$path | string | The path to append to the URI |
Exception | Description |
---|---|
\Zend_Rest_Client_Exception |


_prepareRest(string $path) : void
Call a remote REST web service URI and return the Zend_Http_Response object
Inherited from: \Zend_Rest_Client::_prepareRest()Name | Type | Description |
---|---|---|
$path | string | The path to append to the URI |
Exception | Description |
---|---|
\Zend_Rest_Client_Exception |


_setDate(int | string $value) : void
Set date header
Name | Type | Description |
---|---|---|
$value | int | string |
- Deprecated
- Not supported by Twitter since April 08, 2009


_validInteger(mixed $int) : integer
Protected function to validate that the integer is valid or return a 0
Name | Type | Description |
---|---|---|
$int | mixed |
Type | Description |
---|---|
integer |


_validateScreenName(string $name) : string
Validate a screen name using Twitter rules
Name | Type | Description |
---|---|---|
$name | string |
Type | Description |
---|---|
string |
Exception | Description |
---|---|
\Zend_Service_Twitter_Exception |


accountEndSession() : true
End current session
Type | Description |
---|---|
true |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


accountRateLimitStatus() : \Zend_Rest_Client_Result
Returns the number of api requests you have left per hour.
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


accountVerifyCredentials() : \Zend_Rest_Client_Result
Verify Account Credentials
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


blockBlocking(integer $page = 1, boolean $returnUserIds = false) : \Zend_Rest_Client_Result
Returns an array of user objects that the authenticating user is blocking
Name | Type | Description |
---|---|---|
$page | integer | Optional. Specifies the page number of the results beginning at 1. A single page contains 20 ids. |
$returnUserIds | boolean | Optional. Returns only the userid's instead of the whole user object |
Type | Description |
---|---|
\Zend_Rest_Client_Result |


blockCreate(integer | string $id) : \Zend_Rest_Client_Result
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_Rest_Client_Result |


blockDestroy(integer | string $id) : \Zend_Rest_Client_Result
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_Rest_Client_Result |


blockExists(string | integer $id, boolean $returnResult = false) : Boolean | \Zend_Rest_Client_Result
Returns if the authenticating user is blocking a target user.
Name | Type | Description |
---|---|---|
$id | string | integer | The ID or screen_name of the potentially blocked user. |
$returnResult | boolean | Instead of returning a boolean return the rest response from twitter |
Type | Description |
---|---|
Boolean | \Zend_Rest_Client_Result |


directMessageDestroy(int $id) : \Zend_Rest_Client_Result
Destroy a direct message
Name | Type | Description |
---|---|---|
$id | int | ID of message to destroy |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


directMessageMessages(array $params = array()) : \Zend_Rest_Client_Result
Retrieve direct messages for the current user
$params may include one or more of the following keys - since_id: return statuses only greater than the one specified - page: return page X of results
Name | Type | Description |
---|---|---|
$params | array |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


directMessageNew(int | string $user, string $text) : \Zend_Rest_Client_Result
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_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Service_Twitter_Exception | if message is too short or too long |
\Zend_Http_Client_Exception | if HTTP request fails or times out |


directMessageSent(array $params = array()) : \Zend_Rest_Client_Result
Retrieve list of direct messages sent by current user
$params may include one or more of the following keys - since_id: return statuses only greater than the one specified - page: return page X of results
Name | Type | Description |
---|---|---|
$params | array |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


favoriteCreate(int $id) : \Zend_Rest_Client_Result
Mark a status as a favorite
Name | Type | Description |
---|---|---|
$id | int | Status ID you want to mark as a favorite |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


favoriteDestroy(int $id) : \Zend_Rest_Client_Result
Remove a favorite
Name | Type | Description |
---|---|---|
$id | int | Status ID you want to de-list as a favorite |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


favoriteFavorites(array $params = array()) : \Zend_Rest_Client_Result
Fetch favorites
$params may contain one or more of the following: - 'id': Id of a user for whom to fetch favorites - 'page': Retrieve a different page of resuls
Name | Type | Description |
---|---|---|
$params | array |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


friendshipCreate(int | string $id) : \Zend_Rest_Client_Result
Create friendship
Name | Type | Description |
---|---|---|
$id | int | string | User ID or name of new friend |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


friendshipDestroy(int | string $id) : \Zend_Rest_Client_Result
Destroy friendship
Name | Type | Description |
---|---|---|
$id | int | string | User ID or name of friend to remove |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


friendshipExists(int | string $id) : \Zend_Rest_Client_result
Friendship exists
Name | Type | Description |
---|---|---|
$id | int | string | User ID or name of friend to see if they are your friend |
Type | Description |
---|---|
\Zend_Rest_Client_result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


getHttpClient() : \Zend_Http_Client
Gets the HTTP client object.
Inherited from: \Zend_Service_Abstract::getHttpClient()\Zend_Rest_Client::getHttpClient()Type | Description |
---|---|
\Zend_Http_Client |


getLocalHttpClient() : \Zend_Http_Client
Get the local HTTP client as distinct from the static HTTP client inherited from Zend_Rest_Client
Type | Description |
---|---|
\Zend_Http_Client |


restDelete(string $path, $data = null) : \Zend_Http_Response
Name | Type | Description |
---|---|---|
$path | string | |
$data |
Type | Description |
---|---|
\Zend_Http_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |


restGet(string $path, array $query = null) : \Zend_Http_Response
Name | Type | Description |
---|---|---|
$path | string | |
$query | array | Array of GET parameters |
Type | Description |
---|---|
\Zend_Http_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |


restPost(string $path, mixed $data = null) : \Zend_Http_Response
Name | Type | Description |
---|---|---|
$path | string | |
$data | mixed | Raw data to send |
Type | Description |
---|---|
\Zend_Http_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |


restPut(string $path, mixed $data = null) : \Zend_Http_Response
Name | Type | Description |
---|---|---|
$path | string | |
$data | mixed | Raw data to send in request |
Type | Description |
---|---|
\Zend_Http_Response |
Exception | Description |
---|---|
\Zend_Http_Client_Exception |


setHttpClient(\Zend_Http_Client $httpClient) : void
Sets the HTTP client object to use for retrieving the feeds.
Inherited from: \Zend_Service_Abstract::setHttpClient()\Zend_Rest_Client::setHttpClient()If none is set, the default Zend_Http_Client will be used.
Name | Type | Description |
---|---|---|
$httpClient | \Zend_Http_Client |


setLocalHttpClient(\Zend_Http_Client $client) : \Zend_Service_Twitter
Set local HTTP client as distinct from the static HTTP client as inherited from Zend_Rest_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


setNoReset(boolean $bool = true) : void
Tells Zend_Rest_Client not to reset all parameters on it's Zend_Http_Client.
Inherited from: \Zend_Rest_Client::setNoReset()If you want no reset, this must be called explicitly before every request for which you do not want to reset the parameters. Parameters will accumulate between requests, but as soon as you do not call this function prior to any request, all preset parameters will be reset as by default.
Name | Type | Description |
---|---|---|
$bool | boolean |


setUri(string | \Zend_Uri_Http $uri) : \Zend_Rest_Client
Name | Type | Description |
---|---|---|
$uri | string | \Zend_Uri_Http | URI for the web service |
Type | Description |
---|---|
\Zend_Rest_Client |


setUsername(string $value) : \Zend_Service_Twitter
Set username
Name | Type | Description |
---|---|---|
$value | string |
Type | Description |
---|---|
\Zend_Service_Twitter |


statusDestroy(int $id) : \Zend_Rest_Client_Result
Destroy a status message
Name | Type | Description |
---|---|---|
$id | int | ID of status to destroy |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


statusFriendsTimeline(array $params = array()) : void
Friend Timeline Status
$params may include one or more of the following keys - id: ID of a friend whose timeline you wish to receive - count: how many statuses to return - since_id: return results only after the specific tweet - page: return page X of results
Name | Type | Description |
---|---|---|
$params | array |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


statusPublicTimeline() : \Zend_Rest_Client_Result
Public Timeline status
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


statusReplies( $params = array()) : \Zend_Rest_Client_Result
Get status replies
$params may include one or more of the following keys - since_id: return results only after the specified tweet id - page: return page X of results
Name | Type | Description |
---|---|---|
$params |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


statusShow(int $id) : \Zend_Rest_Client_Result
Show a single status
Name | Type | Description |
---|---|---|
$id | int | Id of status to show |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


statusUpdate(string $status, $inReplyToStatusId = null) : \Zend_Rest_Client_Result
Update user's current status
Name | Type | Description |
---|---|---|
$status | string | |
$inReplyToStatusId |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |
\Zend_Service_Twitter_Exception | if message is too short or too long |


statusUserTimeline( $params = array()) : \Zend_Rest_Client_Result
User Timeline status
$params may include one or more of the following keys - id: ID of a friend whose timeline you wish to receive - since_id: return results only after the tweet id specified - page: return page X of results - count: how many statuses to return - max_id: returns only statuses with an ID less than or equal to the specified ID - user_id: specifies the ID of the user for whom to return the user_timeline - screen_name: specfies the screen name of the user for whom to return the user_timeline - include_rts: whether or not to return retweets - trim_user: whether to return just the user ID or a full user object; omit to return full object - include_entities: whether or not to return entities nodes with tweet metadata
Name | Type | Description |
---|---|---|
$params |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


userFollowers(bool $lite = false) : \Zend_Rest_Client_Result
User Followers
Name | Type | Description |
---|---|---|
$lite | bool | If true, prevents inline inclusion of current status for followers; defaults to false |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


userFriends( $params = array()) : \Zend_Rest_Client_Result
User friends
Name | Type | Description |
---|---|---|
$params |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |


userShow(int | string $id) : \Zend_Rest_Client_Result
Show extended information on a user
Name | Type | Description |
---|---|---|
$id | int | string | User ID or name |
Type | Description |
---|---|
\Zend_Rest_Client_Result |
Exception | Description |
---|---|
\Zend_Http_Client_Exception | if HTTP request fails or times out |