SkillAgentSearch skills...

Twitter

Twitter API for Laravel 5.5+, 6.x, 7.x & 8.x

Install / Use

/learn @atymic/Twitter

README

X (formerly Twitter) for PHP

Software License StyleCI Latest Version on Packagist 3.x Downloads 2.x Downloads GitHub Release Date

Twitter API for Laravel 10.x, 11.x (and new versions as they are released). Also supports other frameworks via PHP-DI (or feel free to add support for your framework via PR)

You need to create an application and create your access token in the Application Management.

Installation

composer require atymic/twitter:^3.0 -W

Laravel Configuration

Just set the below environment variables in your .env.

TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET=
TWITTER_API_VERSION=

Advanced Laravel configuration

Run php artisan vendor:publish --provider="Atymic\Twitter\ServiceProvider\LaravelServiceProvider"

/config/twitter.php

Versions

3.x

3.x is the current major version, and is not backward compatible with 2.x.

See the migration guide in UPGRADE.md.

2.x

2.x is not longer maintained. We are not accepting bug fixes, please upgrade to 3.x

Usage

Output format

You can choose between three different output formats. By default, API v1 responses will be returned as objects while API v2 responses will be returned as JSON. To change this, use the response_format option in the parameters you pass to any method.

response_format : object|json|array (v1 default:object) (v2 default:json)

X (formerly Twitter) API Versions

To set the default twitter API version to v2 instead of the default v1.1, set the TWITTER_API_VERSION to 2 in your .env.

If you have set the v1.1 api as the default, you can use use Twitter::forApiV2() to get an instance of the v2 client. The same goes for getting a v1 instance from a v2 client, using Twitter::forApiV1().

It is safe to call Twitter::forApiV1() on either a v1 or v2 client instance.

Functions

X (formerly Twitter) API v1.1

Account

  • getSettings() - Returns settings (including current trend, geo and sleep time information) for the authenticating user.
  • getCredentials()
  • postSettings() - Updates the authenticating user’s settings.
  • postSettingsDevice() - Sets which device Twitter delivers updates to for the authenticating user. Sending none as the device parameter will disable SMS updates.
  • postProfile() - Sets some values that users are able to set under the “Account” tab of their settings page. Only the parameters specified will be updated.
  • postBackground() - Updates the authenticating user’s profile background image. This method can also be used to enable or disable the profile background image.
  • postProfileImage() - Updates the authenticating user’s profile image. Note that this method expects raw multipart data, not a URL to an image.
  • destroyUserBanner() - Removes the uploaded profile banner for the authenticating user. Returns HTTP 200 upon success.
  • postUserBanner() - Uploads a profile banner on behalf of the authenticating user. For best results, upload an profile_banner_url node in their Users objects.

Account Activity (Premium)

  • setWebhook($env, $url) - Registers a webhook url for all event types in the given environment.
  • crcHash($crcToken) - Returns HMAC SHA-256 hash from the given CRC token and consumer secret. You'll need to return this on your webhook (more info).
  • getWebhooks($env) - Returns webhook URLs for the given environment (or all environments if none provided), and their statuses for the authenticating app.
  • updateWebhooks($env, $webhookId) - Triggers the challenge response check (CRC) for the given enviroments webhook for all activites. If the check is successful, returns true and reenables the webhook by setting its status to valid.
  • destroyWebhook($env, $webhookId) - Removes the webhook from the provided application's all activities configuration. Returns true on success.
  • setSubscriptions($env) - Subscribes the provided application to all events for the provided environment for all message types. Returns true on success.
  • getSubscriptions($env) - Returns true if the provided user context has an active subscription with provided application.
  • getSubscriptionsCount() - Returns the count of subscriptions that are currently active on your account for all activities.
  • getSubscriptionsList($env) - Returns a list of the current All Activity type subscriptions.
  • destroyUserSubscriptions($env, $userId) - Deactivates subscription for the specified user id from the environment. Returns true on success.

Block

  • getBlocks() - Returns a collection of user objects that the authenticating user is blocking.
  • getBlocksIds() - Returns an array of numeric user ids the authenticating user is blocking.
  • postBlock() - 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.
  • destroyBlock() - 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.

DirectMessage

  • getDm() - Returns a single direct message event, specified by an id parameter.
  • getDms() - Returns all Direct Message events (both sent and received) within the last 30 days. Sorted in reverse-chronological order.
  • destroyDm() - Destroys the direct message specified in the required ID parameter. The authenticating user must be the recipient of the specified direct message.
  • postDm() - Publishes a new message_create event resulting in a Direct Message sent to a specified user from the authenticating user. Returns an event if successful. Supports publishing Direct Messages with optional Quick Reply and media attachment.

Favorite

  • getFavorites() - Returns the 20 most recent Tweets favorited by the authenticating or specified user.
  • destroyFavorite() - Un-favorites the status specified in the ID parameter as the authenticating user. Returns the un-favorited status in the requested format when successful.
  • postFavorite() - Favorites the status specified in the ID parameter as the authenticating user. Returns the favorite status when successful.

Friendship

  • getNoRters() - Returns a collection of user_ids that the currently authenticated user does not want to receive retweets from.
  • getFriendsIds() - Returns a cursored collection of user IDs for every user following the specified user.
  • getFollowersIds() - Returns a cursored collection of user IDs for every user following the specified user.
  • getFriendshipsIn() - Returns a collection of numeric IDs for every user who has a pending request to follow the authenticating user.
  • getFriendshipsOut() - Returns a collection of numeric IDs for every protected user for whom the authenticating user has a pending follow request.
  • postFollow() - Allows the authenticating users to follow the user specified in the ID parameter.
  • postUnfollow() - Allows the authenticating user to unfollow the user specified in the ID parameter.
  • postFollowUpdate() - Allows one to enable or disable retweets and device notifications from the specified user.
  • getFriendships() - Returns detailed information about the relationship between two arbitrary users.
  • getFriends() - Returns a cursored collection of user objects for every user the specified user is following ( otherwise known as their “friends”).
  • getFollowers() - Returns a cursored collection of user objects for users following the specified user.
  • getFriendshipsLookup() - Returns the relationships of the authenticating user to the comma-separated list of up to 100 screen_names or user_ids provided. Values for connections can be: following, following_requested, followed_by, none, blocking, muting.

Geo

  • getGeo() - Returns all the information about a known place.
  • getGeoReverse() - Given a latitude and a longitude, searches for up to 20 places that can be used as a place_id when updating a status.
  • getGeoSearch() - 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.
  • getGeoSimilar() - Locates places near the given coordinates which are similar in name. Conceptually you would use this method to get a list of known places to choose from first. Then, if the desired place doesn't exist, make a request to POST geo/place to create a new one. The token contained in the response is the token needed to be able to create a new place.

Help

  • postSpam() - Report the specified user as a spam account to X (formerly Twitter). Additionally performs the equivalent of POST blocks / create on behalf of the authenticated user.
  • getHelpConfiguration() - Returns the
View on GitHub
GitHub Stars946
CategoryDevelopment
Updated11h ago
Forks291

Languages

PHP

Security Score

100/100

Audited on Apr 5, 2026

No findings