Twitter class
- Author: Tijs Verkoyen <php-twitter@verkoyen.eu>
- Copyright: Copyright (c), Tijs Verkoyen. All rights reserved.
- License: BSD License
Synopsis
class Twitter
{
- // constants
- const DEBUG = false;
- const API_URL = 'https://api.twitter.com/1.1';
- const SECURE_API_URL = 'https://api.twitter.com';
- const API_PORT = 443;
- const SECURE_API_PORT = 443;
- const VERSION = '2.3.1';
- // members
- protected $curl;
- protected $consumerKey;
- protected $consumerSecret;
- protected string $oAuthToken = '';
- protected string $oAuthTokenSecret = '';
- protected integer $timeOut = 10;
- protected $userAgent;
- // methods
- public void __construct()
- public void __destruct()
- protected string buildQuery()
- protected string calculateBaseString()
- protected string calculateHeader()
- protected array doOAuthCall()
- protected string doCall()
- protected string getConsumerKey()
- protected string getConsumerSecret()
- protected string getOAuthToken()
- protected string getOAuthTokenSecret()
- public int getTimeOut()
- public string getUserAgent()
- protected void setConsumerKey()
- protected void setConsumerSecret()
- public void setOAuthToken()
- public void setOAuthTokenSecret()
- public void setTimeOut()
- public void setUserAgent()
- protected string hmacsha1()
- protected static string urlencode_rfc3986()
- public array statusesMentionsTimeline()
- public array statusesUserTimeline()
- public array statusesHomeTimeline()
- public array statusesRetweetsOfMe()
- public array statusesRetweets()
- public array statusesShow()
- public array statusesDestroy()
- public array statusesUpdate()
- public array statusesRetweet()
- public void statusesUpdateWithMedia()
- public array statusesOEmbed()
- public array searchTweets()
- public void statusesFilter()
- public void statusesSample()
- public void statusesFirehose()
- public void user()
- public void site()
- public array directMessages()
- public array directMessagesSent()
- public array directMessagesShow()
- public array directMessagesDestroy()
- public array directMessagesNew()
- public array friendsIds()
- public array followersIds()
- public array friendshipsLookup()
- public array friendshipsIncoming()
- public array friendshipsOutgoing()
- public array friendshipsCreate()
- public array friendshipsDestroy()
- public array friendshipsUpdate()
- public array friendshipsShow()
- public array friendsList()
- public array followersList()
- public array accountSettings()
- public array accountVerifyCredentials()
- public array accountSettingsUpdate()
- public array accountUpdateDeliveryDevice()
- public array accountUpdateProfile()
- public array accountUpdateProfileBackgroundImage()
- public array accountUpdateProfileColors()
- public array accountUpdateProfileImage()
- public array blocksList()
- public array blocksIds()
- public array blocksCreate()
- public array blocksDestroy()
- public array usersLookup()
- public array usersShow()
- public array usersSearch()
- public array usersContributees()
- public array usersContributors()
- public bool accountRemoveProfileBanner()
- public void accountUpdateProfileBanner()
- public array usersProfileBanner()
- public array usersSuggestionsSlug()
- public array usersSuggestions()
- public array usersSuggestionsSlugMembers()
- public array favoritesList()
- public array favoritesDestroy()
- public array favoritesCreate()
- public void listsList()
- public void listsStatuses()
- public void listsMembersDestroy()
- public void listsMemberships()
- public void listsSubscribers()
- public void listsSubscribersCreate()
- public void listsSubscribersShow()
- public void listsSubscribersDestroy()
- public void listsMembersCreateAll()
- public void listsMembersShow()
- public void listsMembers()
- public void listsMembersCreate()
- public void listsDestroy()
- public void listsUpdate()
- public void listsCreate()
- public void listsShow()
- public void listSubscriptions()
- public void listsMembersDestroyAll()
- public array savedSearchesList()
- public array savedSearchesShow()
- public array savedSearchesCreate()
- public array savedSearchesDestroy()
- public array geoId()
- public array geoReverseGeoCode()
- public array geoSearch()
- public array geoSimilarPlaces()
- public array geoPlace()
- public array trendsPlace()
- public array trendsAvailable()
- public array trendsClosest()
- public array reportSpam()
- public void oAuthAuthenticate()
- public void oAuthAuthorize()
- public array oAuthAccessToken()
- public array oAuthRequestToken()
- public array helpConfiguration()
- public array helpLanguages()
- public array helpPrivacy()
- public array helpTos()
- public string applicationRateLimitStatus()
Tasks
Line | Task |
---|---|
240+ | refactor me |
Constants
Name | Value |
---|---|
DEBUG | false |
API_URL | 'https://api.twitter.com/1.1' |
SECURE_API_URL | 'https://api.twitter.com' |
API_PORT | 443 |
SECURE_API_PORT | 443 |
VERSION | '2.3.1' |
Members
protected
- $consumerKey
—
string
The consumer key - $consumerSecret
—
string
The consumer secret - $curl
—
resource
A cURL instance - $oAuthToken
—
string
The oAuth-token - $oAuthTokenSecret
—
string
The oAuth-token-secret - $timeOut
—
int
The timeout - $userAgent
—
string
The user agent
Methods
protected
- buildQuery() — Format the parameters as a querystring
- calculateBaseString() — All OAuth 1.0 requests use the same basic algorithm for creating a signature base string and a signature. The signature base string is composed of the HTTP method being used, followed by an ampersand ("&") and then the URL-encoded base URL being accessed, complete with path (but not query parameters), followed by an ampersand ("&"). Then, you take all query parameters and POST body parameters (when the POST body is of the URL-encoded type, otherwise the POST body is ignored), including the OAuth parameters necessary for negotiation with the request at hand, and sort them in lexicographical order by first parameter name and then parameter value (for duplicate parameters), all the while ensuring that both the key and the value for each parameter are URL encoded in isolation. Instead of using the equals ("=") sign to mark the key/value relationship, you use the URL-encoded form of "%3D". Each parameter is then joined by the URL-escaped ampersand sign, "%26".
- calculateHeader() — Build the Authorization header
- doCall() — Make the call
- doOAuthCall() — Make an call to the oAuth
- getConsumerKey() — Get the consumer key
- getConsumerSecret() — Get the consumer secret
- getOAuthToken() — Get the oAuth-token
- getOAuthTokenSecret() — Get the oAuth-token-secret
- hmacsha1() — Build the signature for the data
- setConsumerKey() — Set the consumer key
- setConsumerSecret() — Set the consumer secret
- urlencode_rfc3986() — URL-encode method for internal use
public
- __construct() — Default constructor
- __destruct() — Default destructor
- accountRemoveProfileBanner() — Removes the uploaded profile banner for the authenticating user.
- accountSettings() — Returns settings (including current trend, geo and sleep time information) for the authenticating user.
- accountSettingsUpdate() — Updates the authenticating user's settings.
- accountUpdateDeliveryDevice() — Sets which device Twitter delivers updates to for the authenticating user. Sending none as the device parameter will disable SMS updates.
- accountUpdateProfile() — Sets values that users are able to set under the "Account" tab of their settings page. Only the parameters specified will be updated.
- accountUpdateProfileBackgroundImage() — Updates the authenticating user's profile background image.
- accountUpdateProfileBanner() — Not implemented yet
- accountUpdateProfileColors() — Sets one or more hex values that control the color scheme of the authenticating user's profile page on twitter.com.
- accountUpdateProfileImage() — Updates the authenticating user's profile image.
- accountVerifyCredentials() — Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; returns a 401 status code and an error message if not. Use this method to test if supplied user credentials are valid.
- applicationRateLimitStatus() — Returns the current rate limits for methods belonging to the specified resource families.
- blocksCreate() — Blocks the specified user from following the authenticating user. In addition the blocked user will not show in the authenticating users mentions or timeline (unless retweeted by another user). If a follow or friend relationship exists it is destroyed.
- blocksDestroy() — Un-blocks the user specified in the ID parameter for the authenticating user. Returns the un-blocked user in the requested format when successful. If relationships existed before the block was instated, they will not be restored.
- blocksIds() — Returns an array of numeric user ids the authenticating user is blocking.
- blocksList() — Not implemented yet
- directMessages() — Returns the 20 most recent direct messages sent to the authenticating user. Includes detailed information about the sender and recipient user. You can request up to 200 direct messages per call, up to a maximum of 800 incoming DMs.
- directMessagesDestroy() — Destroys the direct message specified in the required ID parameter. The authenticating user must be the recipient of the specified direct message.
- directMessagesNew() — Sends a new direct message to the specified user from the authenticating user. Requires both the user and text parameters and must be a POST. Returns the sent message in the requested format if successful.
- directMessagesSent() — Returns the 20 most recent direct messages sent by the authenticating user. Includes detailed information about the sender and recipient user. You can request up to 200 direct messages per call, up to a maximum of 800 outgoing DMs.
- directMessagesShow()
- favoritesCreate() — Favorites the status specified in the ID parameter as the authenticating user. Returns the favorite status when successful.
- favoritesDestroy() — Un-favorites the status specified in the ID parameter as the authenticating user. Returns the un-favorited status in the requested format when successful.
- favoritesList() — Returns the 20 most recent Tweets favorited by the authenticating or specified user.
- followersIds() — Returns a cursored collection of user IDs for every user following the specified user.
- followersList() — Returns a cursored collection of user objects for users following the specified user.
- friendsIds() — Returns a cursored collection of user IDs for every user the specified user is following (otherwise known as their "friends").
- friendsList() — Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends").
- friendshipsCreate() — Allows the authenticating users to follow the user specified in the ID parameter.
- friendshipsDestroy() — Allows the authenticating user to unfollow the user specified in the ID parameter.
- friendshipsIncoming() — Returns a collection of numeric IDs for every user who has a pending request to follow the authenticating user.
- friendshipsLookup() — Returns the relationships of the authenticating user to the comma-separated list of up to 100 screen_names or user_ids provided.
- friendshipsOutgoing() — Returns a collection of numeric IDs for every protected user for whom the authenticating user has a pending follow request.
- friendshipsShow() — Returns detailed information about the relationship between two arbitrary users.
- friendshipsUpdate() — Allows one to enable or disable retweets and device notifications from the specified user.
- geoId() — Returns all the information about a known place.
- geoPlace() — Creates a new place at the given latitude and longitude.
- geoReverseGeoCode() — Given a latitude and a longitude, searches for up to 20 places that can be used as a place_id when updating a status.
- geoSearch() — Search for places that can be attached to a statuses/update. Given a latitude and a longitude pair, an IP address, or a name, this request will return a list of all the valid places that can be used as the place_id when updating a status.
- geoSimilarPlaces() — Locates places near the given coordinates which are similar in name.
- getTimeOut() — Get the timeout
- getUserAgent() — Get the useragent that will be used. Our version will be prepended to yours.
- helpConfiguration() — Returns the current configuration used by Twitter including twitter.com slugs which are not usernames, maximum photo resolutions, and t.co URL lengths.
- helpLanguages() — Returns the list of languages supported by Twitter along with their ISO 639-1 code. The ISO 639-1 code is the two letter value to use if you include lang with any of your requests.
- helpPrivacy() — Returns Twitter's Privacy Policy
- helpTos() — Returns the Twitter Terms of Service in the requested format. These are not the same as the Developer Rules of the Road.
- listSubscriptions() — Not implemented yet
- listsCreate() — Not implemented yet
- listsDestroy() — Not implemented yet
- listsList() — Not implemented yet
- listsMembers() — Not implemented yet
- listsMembersCreate() — Not implemented yet
- listsMembersCreateAll() — Not implemented yet
- listsMembersDestroy() — Not implemented yet
- listsMembersDestroyAll() — Not implemented yet
- listsMembersShow() — Not implemented yet
- listsMemberships() — Not implemented yet
- listsShow() — Not implemented yet
- listsStatuses() — Not implemented yet
- listsSubscribers() — Not implemented yet
- listsSubscribersCreate() — Not implemented yet
- listsSubscribersDestroy() — Not implemented yet
- listsSubscribersShow() — Not implemented yet
- listsUpdate() — Not implemented yet
- oAuthAccessToken() — Allows a Consumer application to exchange the OAuth Request Token for an OAuth Access Token.
- oAuthAuthenticate() — Allows a Consumer application to use an OAuth request_token to request user authorization.
- oAuthAuthorize() — Will redirect to the page to authorize the applicatione
- oAuthRequestToken() — Allows a Consumer application to obtain an OAuth Request Token to request user authorization.
- reportSpam() — The user specified in the id is blocked by the authenticated user and reported as a spammer.
- savedSearchesCreate() — Create a new saved search for the authenticated user. A user may only have 25 saved searches.
- savedSearchesDestroy() — Destroys a saved search for the authenticating user. The authenticating user must be the owner of saved search id being destroyed.
- savedSearchesList() — Returns the authenticated user's saved search queries.
- savedSearchesShow() — Retrieve the information for the saved search represented by the given id. The authenticating user must be the owner of saved search ID being requested.
- searchTweets() — Returns tweets that match a specified query.
- setOAuthToken() — Set the oAuth-token
- setOAuthTokenSecret() — Set the oAuth-secret
- setTimeOut() — Set the timeout
- setUserAgent() — Get the useragent that will be used. Our version will be prepended to yours.
- site() — Not implemented yet
- statusesDestroy() — Destroys the status specified by the required ID parameter. The authenticating user must be the author of the specified status. Returns the destroyed status if successful.
- statusesFilter() — Not implemented yet
- statusesFirehose() — Not implemented yet
- statusesHomeTimeline() — Returns the 20 most recent statuses, including retweets if they exist, posted by the authenticating user and the user's they follow. This is the same timeline seen by a user when they login to twitter.com.
- statusesMentionsTimeline() — Returns the 20 most recent mentions (tweets containing a users's @screen_name) for the authenticating user.
- statusesOEmbed()
- statusesRetweet() — Retweets a tweet. Returns the original tweet with retweet details embedded.
- statusesRetweets() — Returns up to 100 of the first retweets of a given tweet.
- statusesRetweetsOfMe() — Returns the most recent tweets authored by the authenticating user that have recently been retweeted by others. This timeline is a subset of the user's GET statuses/user_timeline.
- statusesSample() — Not implemented yet
- statusesShow() — Returns a single Tweet, specified by the id parameter. The Tweet's author will also be embedded within the tweet.
- statusesUpdate() — Updates the authenticating user's status. A status update with text identical to the authenticating user's text identical to the authenticating user's current status will be ignored to prevent duplicates.
- statusesUpdateWithMedia() — Not implemented yet
- statusesUserTimeline() — Returns a collection of the most recent Tweets posted by the user indicated by the screen_name or user_id parameters.
- trendsAvailable() — Returns the locations that Twitter has trending topic information for.
- trendsClosest() — Returns the locations that Twitter has trending topic information for, closest to a specified location.
- trendsPlace() — Returns the top 10 trending topics for a specific WOEID, if trending information is available for it.
- user() — Not implemented yet
- usersContributees() — Returns a collection of users that the specified user can "contribute" to.
- usersContributors() — Returns a collection of users who can contribute to the specified account.
- usersLookup() — Returns fully-hydrated user objects for up to 100 users per request, as specified by comma-separated values passed to the user_id and/or screen_name parameters.
- usersProfileBanner() — Returns a map of the available size variations of the specified user's profile banner. If the user has not uploaded a profile banner, a HTTP 404 will be served instead.
- usersSearch() — Run a search for users similar to the Find People button on Twitter.com; the same results returned by people search on Twitter.com will be returned by using this API.
- usersShow() — Returns a variety of information about the user specified by the required user_id or screen_name parameter.
- usersSuggestions() — Access to Twitter's suggested user list. This returns the list of suggested user categories. The category can be used in usersSuggestionsSlug to get the users in that category.
- usersSuggestionsSlug() — Access the users in a given category of the Twitter suggested user list.
- usersSuggestionsSlugMembers() — Access the users in a given category of the Twitter suggested user list and return their most recent status if they are not a protected user.