The library has been designed to send request to the Twitter API. In order to do that, you will need a Twitter client. This one needs itself an OAuth client to sign request & an access token. If you want to learn more about this access token, you can read this documentation.
So, first, create your Twitter client:
use Widop\HttpAdapter\CurlHttpAdapter;
use Widop\Twitter\OAuth;
use Widop\Twitter\Rest\Statuses\StatusesUpdateRequest;
use Widop\Twitter\Rest\Twitter;
$oauth = new OAuth\OAuth(
new CurlHttpAdapter(),
new OAuth\OAuthConsumer('consumer_key', 'consumer_secret'),
new OAuth\Signature\OAuthHmacSha1Signature()
);
$token = new OAuth\Token\OAuthToken('oauth_key', 'oauth_secret');
$twitter = new Twitter($oauth, $token);
Note that is also possible to pass a "bearer" token (eg: application access token):
use Widop\Twitter\OAuth\Token\BearerToken;
$twitter->setToken(new BearerToken('foo'));
Here, a simple example where we will destroy the tweet "123":
use Widop\Twitter\OAuth\OAuthException,
use Widop\Twitter\Rest\Statuses\StatusesDestroyRequest;
$request = new StatusesDestroyRequest('123');
try {
$response = $twitter->send($request);
} catch (OAuthException $e) {
// Something goes wrong.
} catch (\Exception $e) {
// Something goes very wrong.
}
The send
method returns a Widop\Twitter\OAuth\OAuthResponse
which gives you access to the decoded response data,
the underlying http response, the current rate limits and more:
$httpResponse = $response->getHttpResponse();
$data = $response->getData();
$id = $response->getData('id');
$limit = $response->getRateLimitLimit();
$remaining = $response->getRateLimitRemaining();
$reset = $response->getRateLimitReset();
$format = $response->getFormat();
Additionally, it allows you to send all the available requests which are listed here:
-
Timeline
-
/statuses/home_timeline
: Returns the authenticated user's tweets and retweets. -
/statuses/mentions_timeline
: Returns the tweets mentioning the authenticated user. -
/statuses/retweets_of_me
: Returns the most recent tweets authored by the authenticating user that have been retweeted by others. -
/statuses/user_timeline
: Returns the tweets of a user's timeline. -
Tweets
-
/statuses/destroy/:id
: Destroys the status specified by the required id parameter. -
/statuses/oembed
: Returns information allowing the creation of an embedded representation of a Tweet on third party sites. -
/statuses/retweet/:id
: Retweets a tweet. Returns the original tweet with retweet details embedded. -
/statuses/retweets/:id
: Returns a collection of the 100 most recent retweets of the tweet specified by the id parameter. -
/statuses/retweeters/ids
: Returns a collection of up to 100 user IDs belonging to users who have retweeted the tweet. -
/statuses/show/:id
: Returns a single Tweet, specified by the id parameter. -
/statuses/update
: Updates the authenticating user's current status, also known as tweeting. -
/statuses/update_with_media
: Updates the authenticating user's current status, also known as tweeting with a media. -
Search
-
/search/tweets
: Returns a collection of relevant Tweets matching a specified query. -
Direct Messages
-
/direct_messages
: Returns the 20 most recent direct messages sent to the authenticating user. -
/direct_messages/destroy
: Destroys the direct message specified in the required ID parameter. -
/direct_messages/new
: Sends a new direct message to the specified user from the authenticating user. -
/direct_messages/sent
: Returns the 20 most recent direct messages sent to the authenticating user. -
/direct_messages/show
: Returns a single direct message, specified by an id parameter. -
Friends & followers
-
/favorites/ids
: Returns a cursored collection of user IDs for every user following the specified user. -
/favorites/list
: Returns a cursored collection of user objects for users following the specified user. -
/friends/ids
: Returns a cursored collection of user IDs for every user the specified user is following. -
/friends/list
: Returns a cursored collection of user objects for every user the specified user is following. -
/friendships/create
: Allows the authenticating users to follow the user specified in the ID parameter. -
/friendships/destroy
: Allows the authenticating user to unfollow the user specified in the ID parameter. -
/friendships/incoming
: Returns a collection of numeric IDs for every user who has a pending request to follow the authenticating user. -
/friendships/lookup
: Returns the relationships of the authenticating user to the comma-separated list of up to 100 screen_names or user_ids provided. -
/friendships/no_retweets_ids
: Returns a collection of user_ids that the currently authenticated user does not want to receive retweets from. -
/friendships/outgoing
: Returns a collection of numeric IDs for every protected user for whom the authenticating user has a pending follow request. -
/friendships/show
: Returns detailed information about the relationship between two arbitrary users. -
/friendships/update
: Allows one to enable or disable retweets and device notifications from the specified user. -
Account
-
GET /account/settings
: Returns settings (including current trend, geo and sleep time information) for the authenticating user. -
POST /account/settings
: Updates the authenticating user's settings. -
/account/remove_profile_banner
: Removes the uploaded profile banner for the authenticating user -
/account/update_delivery_device
: Sets which device Twitter delivers updates to for the authenticating user. -
/account/update_profile
: Sets values that users are able to set under the "Account" tab of their settings page. -
/account/update_profile_background_image
: Updates the authenticating user's profile background image. -
/account/update_profile_banner
: Uploads a profile banner on behalf of the authenticating user. -
/account/update_profile_colors
: Allows one to enable or disable retweets and device notifications from the specified user. -
/account/update_profile_image
: Updates the authenticating user's profile image. -
/account/verify_credentials
: Use this method to test if supplied user credentials are valid. -
Users
-
/users/contributees
: Returns a collection of users that the specified user can "contribute" to. -
/users/contributors
: Returns a collection of users who can contribute to the specified account. -
/users/lookup
: 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. -
/users/profile_banner
: Returns a map of the available size variations of the specified user's profile banner. -
/users/search
: Provides a simple, relevance-based search interface to public user accounts on Twitter. -
/users/show
: Returns a variety of information about the user specified by the required user_id or screen_name parameter. -
Blocks
-
/blocks/create
: Blocks the specified user from following the authenticating user. -
/blocks/destroy
: Un-blocks the user specified in the ID parameter for the authenticating user. -
/blocks/ids
: Returns an array of numeric user ids the authenticating user is blocking. -
/blocks/list
: Returns a collection of user objects that the authenticating user is blocking. -
Suggested Users
-
/users/suggestions
: Access to Twitter's suggested user list. -
/users/suggestions/:slug
: Access the users in a given category of the Twitter suggested user list. -
/users/suggestions/:slug/members
: 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. -
Favorites
-
/favorites/create
: Favorites the status specified in the ID parameter as the authenticating user. -
/favorites/destroy
: Un-favorites the status specified in the ID parameter as the authenticating user. -
/favorites/list
: Returns the 20 most recent Tweets favorited by the authenticating or specified user. -
Lists
-
/lists/create
: Creates a new list for the authenticated user. -
/lists/destroy
: Deletes the specified list. -
/lists/list
: Returns all lists the authenticating or specified user subscribes to, including their own. -
/lists/members
: Returns the members of the specified list. -
/lists/members/create
: Add a member to a list. -
/lists/members/create_all
: Adds multiple members to a list, by specifying a comma-separated list of member ids or screen names. -
/lists/members/destroy
: Removes the specified member from the list. -
/lists/members/destroy_all
: Removes multiple members from a list, by specifying a comma-separated list of member ids or screen names. -
/lists/members/show
: Check if the specified user is a member of the specified list. -
/lists/memberships
: Returns the lists the specified user has been added to. -
/lists/ownerships
: Returns the lists owned by the specified Twitter user. -
/lists/show
: Returns the specified list. -
/lists/statuses
: Returns a timeline of tweets authored by members of the specified list. -
/lists/subscribers
: Returns the subscribers of the specified list. -
/lists/subscribers/create
: Subscribes the authenticated user to the specified list. -
/lists/subscribers/destroy
: Unsubscribes the authenticated user from the specified list. -
/lists/subscribers/show
: Check if the specified user is a subscriber of the specified list. -
/lists/subscriptions
: Obtain a collection of the lists the specified user is subscribed to. -
/lists/update
: Updates the specified list. -
Saved Searches
-
saved_searches/list
: Returns the authenticated user's saved search queries. -
saved_searches/show/:id
: Retrieve the information for the saved search represented by the given id. -
saved_searches/create
: Create a new saved search for the authenticated user. -
saved_searches/destroy/:id
: Destroys a saved search for the authenticating user. -
Places & Geo
-
geo/id/:place_id
: Returns all the information about a known place. -
geo/reverse_geocode
: Given a latitude and a longitude, searches for up to 20 places that can be used as a place_id when updating a status. -
geo/search
: Search for places that can be attached to a statuses/update. -
geo/similar_places
: Locates places near the given coordinates which are similar in name. -
Trends
-
/trends/available
: Returns the locations that Twitter has trending topic information for. -
/trends/closest
: Returns the locations that Twitter has trending topic information for, closest to a specified location. -
/trends/place
: Returns the top 10 trending topics for a specific WOEID, if trending information is available for it. -
Spam Reporting
-
/users/spam_report
: Report the specified user as a spam account to Twitter. -
Application & Help
Obviously, if you want to complete the list, you're welcome :)