category Zend
package Zend_Service
subpackage Twitter
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License

 Methods

Method overloading

__call(string $method, array $params) : mixed

Parameters

$method

string

$params

array

Exceptions

\Exception\BadMethodCallException if unable to find method

Returns

mixed

Constructor

__construct(null|array|\Zend_Config $options = null, null|\Zend_Oauth_Consumer $consumer = null, null|\Zend_Http_Client $httpClient = null

Parameters

$options

nullarray\Zend_Config

$consumer

null\Zend_Oauth_Consumer

$httpClient

null\Zend_Http_Client

Proxy service methods

__get(string $type) : \Twitter

Parameters

$type

string

Exceptions

\Exception\DomainException If method not in method types list

Returns

\Twitter

Verify Account Credentials

accountVerifyCredentials() : \Zend_Service_Twitter_Response

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Returns the number of api requests you have left per hour.

applicationRateLimitStatus() : \Zend_Service_Twitter_Response
todo Have a separate payload object to represent rate limits

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Blocks the user specified in the ID parameter as the authenticating user.

blocksCreate(integer|string $id) : \Zend_Service_Twitter_Response

Destroys a friendship to the blocked user if it exists.

Parameters

$id

integerstring

The ID or screen name of a user to block.

Exceptions

\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Un-blocks the user specified in the ID parameter for the authenticating user

blocksDestroy(integer|string $id) : \Zend_Service_Twitter_Response

Parameters

$id

integerstring

The ID or screen_name of the user to un-block.

Exceptions

\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Returns an array of user ids that the authenticating user is blocking

blocksIds(integer $cursor = -1) : \Zend_Service_Twitter_Response

Parameters

$cursor

integer

Optional. Specifies the cursor position at which to begin listing ids; defaults to first "page" of results.

Exceptions

\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Returns an array of user objects that the authenticating user is blocking

blocksList(integer $cursor = -1) : \Zend_Service_Twitter_Response

Parameters

$cursor

integer

Optional. Specifies the cursor position at which to begin listing ids; defaults to first "page" of results.

Exceptions

\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Destroy a direct message

directMessagesDestroy(integer $id) : \Zend_Service_Twitter_Response

Parameters

$id

integer

ID of message to destroy

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Retrieve direct messages for the current user

directMessagesMessages(array $options = array()) : \Zend_Service_Twitter_Response

$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

Parameters

$options

array

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Send a direct message to a user

directMessagesNew(integer|string $user, string $text) : \Zend_Service_Twitter_Response

Parameters

$user

integerstring

User to whom to send message

$text

string

Message to send to user

Exceptions

\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

Returns

\Zend_Service_Twitter_Response

Retrieve list of direct messages sent by current user

directMessagesSent(array $options = array()) : \Zend_Service_Twitter_Response

$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

Parameters

$options

array

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Mark a status as a favorite

favoritesCreate(integer $id) : \Zend_Service_Twitter_Response

Parameters

$id

integer

Status ID you want to mark as a favorite

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Remove a favorite

favoritesDestroy(integer $id) : \Zend_Service_Twitter_Response

Parameters

$id

integer

Status ID you want to de-list as a favorite

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Fetch favorites

favoritesList(array $options = array()) : \Zend_Service_Twitter_Response

$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

Parameters

$options

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Create friendship

friendshipsCreate(integer|string $id, array $params = array()) : \Zend_Service_Twitter_Response

Parameters

$id

integerstring

User ID or name of new friend

$params

array

Additional parameters to pass

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Destroy friendship

friendshipsDestroy(integer|string $id) : \Zend_Service_Twitter_Response

Parameters

$id

integerstring

User ID or name of friend to remove

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Get the HTTP client

getHttpClient() : \Zend_Http_Client

Lazy loads one if none present

Returns

\Zend_Http_Client

Retrieve username

getUsername() : string

Returns

string

Checks for an authorised state

isAuthorised() : boolean

Returns

boolean

Search tweets

searchTweets(string $query, array $options = array()) : \Zend_Service_Twitter_Response

$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

Parameters

$query

string

$options

array

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Set HTTP client

setHttpClient(\Zend_Http_Client $client) : \Zend_Service_Twitter
fluent This method is part of a fluent interface and will return the same instance

Parameters

$client

\Zend_Http_Client

Returns

\Zend_Service_Twitter

Set username

setUsername(string $value) : \Zend_Service_Twitter
fluent This method is part of a fluent interface and will return the same instance

Parameters

$value

string

Returns

\Zend_Service_Twitter

Destroy a status message

statusesDestroy(integer $id) : \Zend_Service_Twitter_Response

Parameters

$id

integer

ID of status to destroy

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Friend Timeline Status

statusesHomeTimeline(array $options = array()) : \Zend_Service_Twitter_Response

$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

Parameters

$options

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Get status replies

statusesMentionsTimeline(array $options = array()) : \Zend_Service_Twitter_Response

$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

Parameters

$options

array

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Public Timeline status

statusesSample() : \Zend_Service_Twitter_Response

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Show a single status

statusesShow(integer $id) : \Zend_Service_Twitter_Response

Parameters

$id

integer

Id of status to show

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Update user's current status

statusesUpdate(string $status, null|integer $inReplyToStatusId = null) : \Zend_Service_Twitter_Response
todo Support additional parameters supported by statuses/update endpoint

Parameters

$status

string

$inReplyToStatusId

nullinteger

Exceptions

\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

Returns

\Zend_Service_Twitter_Response

User Timeline status

statusesUserTimeline(array $options = array()) : \Zend_Service_Twitter_Response

$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

Parameters

$options

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Search users

usersSearch(string $query, array $options = array()) : \Zend_Service_Twitter_Response

$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

Parameters

$query

string

$options

array

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Show extended information on a user

usersShow(integer|string $id) : \Zend_Service_Twitter_Response

Parameters

$id

integerstring

User ID or name

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out
\Exception\DomainException if unable to decode JSON payload

Returns

\Zend_Service_Twitter_Response

Create a parameter representing the user

createUserParameter(integer|string $id, array $params) : array

Determines if $id is an integer, and, if so, sets the "user_id" parameter. If not, assumes the $id is the "screen_name".

Parameters

$id

integerstring

$params

array

Returns

array

Performs an HTTP GET request to the $path.

get(string $path, array $query = array()) : \Zend_Http_Response

Parameters

$path

string

$query

array

Array of GET parameters

Exceptions

\Zend_Http_Client_Exception

Returns

\Zend_Http_Response

Initialize HTTP authentication

init() : void

Exceptions

\Exception\DomainException if unauthorised

Perform a POST or PUT

performPost(mixed $method, mixed $data, \Zend_Http_Client $client) : \Zend_Http_Response

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.

Parameters

$method

mixed

$data

mixed

$client

Returns

\Zend_Http_Response

Performs an HTTP POST request to $path.

post(string $path, mixed $data = null) : \Zend_Http_Response

Parameters

$path

string

$data

mixed

Raw data to send

Exceptions

\Zend_Http_Client_Exception

Returns

\Zend_Http_Response

Call a remote REST web service URI

prepare(string $path, \Zend_Http_Client $client) : void

Parameters

$path

string

The path to append to the URI

$client

\Zend_Http_Client

Exceptions

\Zend_Http_Client_Exception

Protected function to validate that the integer is valid or return a 0

validInteger($int) : integer

Parameters

$int

Exceptions

\Zend_Http_Client_Exception if HTTP request fails or times out

Returns

integer

Validate a screen name using Twitter rules

validateScreenName(string $name) : string

Parameters

$name

string

Exceptions

\Exception\InvalidArgumentException

Returns

string

 Properties

 

$cookieJar

$cookieJar : array

Default

 

Date format for 'since' strings

$dateFormat : string

Default

'D, d M Y H:i:s T'
 

$httpClient

$httpClient : \Zend_Http_Client

Default

null
 

Current method type (for method proxying)

$methodType : string

Default

 

Types of API methods

$methodTypes : array

Default

array('account', 'application', 'blocks', 'directmessages', 'favorites', 'friendships', 'search', 'statuses', 'users')
 

Oauth Consumer

$oauthConsumer : \Zend_Oauth_Consumer

Default

null
 

Options passed to constructor

$options : array

Default

array()
 

Username

$username : string

Default

 Constants

 

Base URI for all API calls

API_BASE_URI = 'https://api.twitter.com/1.1/' 
 

OAuth Endpoint

OAUTH_BASE_URI = 'https://api.twitter.com/oauth' 
 

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).

STATUS_MAX_CHARACTERS = 246 

This should be reviewed in the future...