PHPackages                             codechap/x - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. codechap/x

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

codechap/x
==========

Posts to your own X profile only.

v2(3mo ago)121MITPHPPHP ^8.2

Since Jan 5Pushed 3mo agoCompare

[ Source](https://github.com/codeChap/post.x)[ Packagist](https://packagist.org/packages/codechap/x)[ RSS](/packages/codechap-x/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (4)Used By (0)

PHP X (Everything App) API Library v2
=====================================

[](#php-x-everything-app-api-library-v2)

A PHP library for the X (formerly Twitter) API v2. Supports posting, media uploads (images, GIFs, video), threads, likes, retweets, follows, timeline, search, and direct messages.

Requirements
------------

[](#requirements)

- PHP 8.2 or higher

Installation
------------

[](#installation)

```
composer require codechap/x
```

Code Quality
------------

[](#code-quality)

This library passes PHPStan analysis at level 8 (strictest level).

```
./vendor/bin/phpstan analyse
```

Setup
-----

[](#setup)

All methods require OAuth 1.0a credentials from [developer.x.com](https://developer.x.com/):

```
use codechap\x\X;

$x = new X();
$x->set('apiKey', 'your-api-key');
$x->set('apiKeySecret', 'your-api-key-secret');
$x->set('accessToken', 'your-access-token');
$x->set('accessTokenSecret', 'your-access-token-secret');
```

Posting Tweets
--------------

[](#posting-tweets)

```
// Simple text tweet
$x->post('Hello, X!');

// Reply to a tweet
$x->post('This is a reply', '1234567890');
```

Posting with Media
------------------

[](#posting-with-media)

```
use codechap\x\Msg;

// Single image with alt text
$msg = new Msg();
$msg->set('content', 'Check this out!');
$msg->set('image', '/path/to/photo.jpg');
$msg->set('altText', 'A description of the image');
$x->post($msg);

// Multiple media (up to 4 images, or 1 GIF, or 1 video)
$msg = new Msg();
$msg->set('content', 'Multiple photos!');
$msg->set('media', [
    ['path' => '/path/to/photo1.jpg', 'alt_text' => 'First photo'],
    ['path' => '/path/to/photo2.png', 'alt_text' => 'Second photo'],
]);
$x->post($msg);

// Upload video
$msg = new Msg();
$msg->set('content', 'Watch this video!');
$msg->set('image', '/path/to/video.mp4');
$x->post($msg);
```

Threads
-------

[](#threads)

```
$threadA = new Msg();
$threadA->set('content', 'Thread part 1');
$threadA->set('image', '/path/to/image.jpg');

$threadB = new Msg();
$threadB->set('content', 'Thread part 2');

$x->post([$threadA, $threadB]);
```

Standalone Media Upload
-----------------------

[](#standalone-media-upload)

```
// Upload media separately (returns media_id for use in tweets)
$result = $x->uploadMedia('/path/to/image.jpg', 'Alt text here');
echo $result['media_id'];

// Supported: JPEG, PNG, WebP (5MB), GIF (15MB), MP4 (512MB)
```

Tweet Actions
-------------

[](#tweet-actions)

```
$x->deleteTweet('1234567890');
$x->likeTweet('1234567890');
$x->unlikeTweet('1234567890');
$x->retweet('1234567890');
$x->unretweet('1234567890');
```

User Lookup
-----------

[](#user-lookup)

```
// Get your own profile
$me = $x->me();
echo $me['data']['name'];

// Look up by username
$user = $x->lookupUser('elonmusk');
echo $user['data']['id'];

// Look up by ID
$user = $x->lookupUserById('44196397');
```

Follow / Unfollow
-----------------

[](#follow--unfollow)

```
// Accepts username or user ID
$x->followUser('@someuser');
$x->unfollowUser('someuser');

// Get followers (paginated)
$result = $x->getFollowers('someuser', 100);
foreach ($result['users'] as $user) {
    echo $user['username'] . "\n";
}
// Use $result['next_token'] for next page

// Get ALL followers (auto-paginates)
$allFollowers = $x->getAllFollowers('someuser');

// Same for following
$result = $x->getFollowing('someuser');
$allFollowing = $x->getAllFollowing('someuser');
```

Timeline
--------

[](#timeline)

```
// Get home timeline
$timeline = $x->getTimeline(20);
foreach ($timeline['tweets'] as $tweet) {
    echo "@{$tweet['username']}: {$tweet['text']}\n";
}

// Exclude retweets and/or replies
$timeline = $x->getTimeline(20, null, 'retweets,replies');
```

Search
------

[](#search)

```
// Search recent tweets (last 7 days)
$results = $x->searchTweets('php programming', 10, 'recency');
foreach ($results['tweets'] as $tweet) {
    echo "@{$tweet['username']}: {$tweet['text']}\n";
}
```

Direct Messages
---------------

[](#direct-messages)

```
// Get DM events
$dms = $x->getDmEvents(20);
foreach ($dms['events'] as $event) {
    echo "{$event['sender_id']}: {$event['text']}\n";
}

// Send a DM
$x->sendDm('conversation-id', 'Hello there!');
```

OAuth Login Flow
----------------

[](#oauth-login-flow)

```
// Step 1: Get authorization URL
$authUrl = $x->getAuthUrlFor('http://localhost:8080/callback');
// Redirect user to $authUrl

// Step 2: Handle callback
$tokens = $x->handleCallback($oauthToken, $oauthVerifier, $callbackUrl);
// Save $tokens['access_token'] and $tokens['access_token_secret']
```

API Reference
-------------

[](#api-reference)

MethodDescription`me()`Get authenticated user's profile`lookupUser($username)`Look up user by username`lookupUserById($id)`Look up user by ID`post($message, $replyTo)`Post tweet, thread, or reply`deleteTweet($id)`Delete a tweet`likeTweet($id)`Like a tweet`unlikeTweet($id)`Unlike a tweet`retweet($id)`Retweet`unretweet($id)`Undo retweet`uploadMedia($path, $altText)`Upload media file`followUser($user)`Follow a user`unfollowUser($user)`Unfollow a user`getFollowers($user, $max, $token)`Get followers (paginated)`getFollowing($user, $max, $token)`Get following (paginated)`getAllFollowers($user)`Get all followers`getAllFollowing($user)`Get all following`getTimeline($max, $token, $exclude)`Get home timeline`searchTweets($query, $max, $sort, $token)`Search recent tweets`getDmEvents($max, $token)`Get DM events`sendDm($conversationId, $text)`Send a direct message`getAuthUrlFor($callback)`Get OAuth authorization URL`handleCallback($token, $verifier, $callback)`Exchange OAuth tokensMedia Limits
------------

[](#media-limits)

TypeMax SizeFormatsImage5 MBJPEG, PNG, WebPAnimated GIF15 MBGIFVideo512 MBMP4- Max 4 images per tweet, OR 1 GIF, OR 1 video (no mixing)
- Chunked upload is used automatically for GIFs, videos, and large files

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance81

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~40 days

Total

3

Last Release

99d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb9295442ae3080252d831794578a67b53968136834c0ebb1878d4f495a1f79a?d=identicon)[CodeChap](/maintainers/CodeChap)

---

Top Contributors

[![codeChap](https://avatars.githubusercontent.com/u/451621?v=4)](https://github.com/codeChap "codeChap (16 commits)")

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/codechap-x/health.svg)

```
[![Health](https://phpackages.com/badges/codechap-x/health.svg)](https://phpackages.com/packages/codechap-x)
```

###  Alternatives

[julien-c/iso3166

ISO 3166-1 alpha-2 mapping

652.6M2](/packages/julien-c-iso3166)[camspiers/statistical-classifier

A PHP implementation of Complement Naive Bayes and SVM statistical classifiers, including a structure for building other classifier, multiple data sources and multiple caching backends

17337.0k1](/packages/camspiers-statistical-classifier)[tapp/filament-google-autocomplete-field

Filament plugin that provides a Google Autocomplete field

30136.4k](/packages/tapp-filament-google-autocomplete-field)[symfony/ux-leaflet-map

Symfony UX Map Leaflet Bridge

14191.0k2](/packages/symfony-ux-leaflet-map)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
