PHPackages                             kawakami-o3/cowitter - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. kawakami-o3/cowitter

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

kawakami-o3/cowitter
====================

Asynchronous Twitter client compatible with mpyw/co Generator-based flows.

v1.0.3.2(8y ago)05MITPHPPHP &gt;=5.5.0

Since Aug 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/kawakami-o3/cowitter)[ Packagist](https://packagist.org/packages/kawakami-o3/cowitter)[ RSS](/packages/kawakami-o3-cowitter/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (7)Versions (8)Used By (0)

**NOTE**

**This project is forked for my own use. The dependency is less restrictive than the original project's one, and it maybe cause a problem which I will NOT fix.**

cowitter [![Build Status](https://camo.githubusercontent.com/1b45ff0fe61f0015c1781a584e062be1d66c772283339ee52db58906064c0c8c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d7079772f636f7769747465722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mpyw/cowitter/build-status/master) [![Code Coverage](https://camo.githubusercontent.com/dc2c9f600fdf6a88d32bd3a1ffaa5f623644dc6fd695a02c50bceea3f9852ccc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d7079772f636f7769747465722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mpyw/cowitter/?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/eeb00c5a1a46602faa0e7247e4ddccef8438ac8dba3c37cffa8f713f939d66be/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d7079772f636f7769747465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mpyw/cowitter/?branch=master)
=================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#cowitter---)

Asynchronous Twitter client compatible with mpyw/co Generator-based flows.

PHP❓Feature Restriction7.0~😄Full Support5.5~5.6😧Generator is not so cool~5.4💥IncompatibleInstalling
----------

[](#installing)

```
composer require mpyw/cowitter:^1.0

```

Tutorial
--------

[](#tutorial)

1. [Preparation](tutorial/01-preparation.md)
2. [Example: Application for your own personal use](tutorial/02-example_application_for_your_own_personal_use.md)
3. [Example: Sign in with Twitter](tutorial/03-example_sign_in_with_twitter.md)
4. [Example: Commandline streaming readers](tutorial/04-example_commandline_streaming_readers.md)

Quick examples
--------------

[](#quick-examples)

### Prepare requirements

[](#prepare-requirements)

```
require __DIR__ . '/vendor/autoload.php';

use mpyw\Co\Co;
use mpyw\Co\CURLException;
use mpyw\Cowitter\Client;
use mpyw\Cowitter\HttpException;
```

### Create client

[](#create-client)

```
$client = new Client(['CK', 'CS', 'AT', 'ATS']);
```

### Synchronous requests

[](#synchronous-requests)

```
// Search tweets
$statuses = $client->get('search/tweets', ['q' => 'cowitter'])->statuses;
var_dump($statuses);
```

```
// Update tweet
$client->post('statuses/update', ['status' => 'Cowitter is the best twitter library for PHP!']);
```

```
// Update tweet with multiple images
$ids = [
    $client->postMultipart('media/upload', ['media' => new \CURLFile('photo01.png')])->media_id_string,
    $client->postMultipart('media/upload', ['media' => new \CURLFile('photo02.jpg')])->media_id_string,
];
$client->post('statuses/update', [
    'status' => 'My photos',
    'media_ids' => implode(',', $ids),
]);
```

```
// Listen user streaming
$client->streaming('user', function ($status) {
    if (!isset($status->text)) return;
    printf("%s(@s) - %s\n",
        $status->user->name,
        $status->user->screen_name,
        htmlspecialchars_decode($status->text, ENT_NOQUOTES)
    );
});
```

### Asynchronous requests

[](#asynchronous-requests)

```
// Search tweets
Co::wait(function () use ($client) {
    $statuses = (yield $client->getAsync('search/tweets', ['q' => 'cowitter']))->statuses;
    var_dump($statuses);
});
```

```
// Rapidly update tweets for 10 times
$tasks = [];
for ($i = 0; $i < 20; ++$i) {
    $tasks[] = $client->postAsync('statuses/update', [
        'status' => str_repeat('!', $i + 1),
    ]);
}
Co::wait($tasks);
```

```
// Rapidly update tweet with multiple images
Co::wait(function () use ($client) {
    $info = yield [
        $client->postMultipartAsync('media/upload', ['media' => new \CURLFile('photo01.png')]),
        $client->postMultipartAsync('media/upload', ['media' => new \CURLFile('photo02.png')]),
    ];
    yield $client->postAsync('statuses/update', [
        'status' => 'My photos',
        'media_ids' => implode(',', array_column($info, 'media_id_string')),
    ]);
});
```

```
// Listen filtered streaming to favorite/retweet at once each tweet
Co::wait($client->streamingAsync('statuses/filter', function ($status) use ($client) {
    if (!isset($status->text)) return;
    printf("%s(@s) - %s\n",
        $status->user->name,
        $status->user->screen_name,
        htmlspecialchars_decode($status->text, ENT_NOQUOTES)
    );
    yield Co::SAFE => [ // ignore errors
        $client->postAsync('favorites/create', ['id' => $status->id_str]),
        $client->postAsync("statuses/retweet/{$status->id_str}"),
    ];
}, ['track' => 'PHP']));
```

```
// Rapidly update with MP4 video
Co::wait(function () use ($client) {
    $file = new \SplFileObject('video.mp4', 'rb');
    $on_uploading = function ($percent) {
        echo "Uploading ... ({$percent}%)\n";
    };
    $on_processing = function ($percent) {
        echo "Processing ... ({$percent}%)\n";
    };
    yield $client->postAsync('statuses/update', [
        'status' => 'My video',
        'media_ids' => (yield $client->uploadVideoAsync($file, $on_uploading, $on_processing))->media_id_string,
    ]);
    echo "Done\n";
});
```

### Handle exceptions

[](#handle-exceptions)

```
try {

    // do stuff here
    $client->get(...);
    $client->post(...);

} catch (HttpException $e) {

    // cURL communication successful but something went wrong with Twitter APIs.
    $message = $e->getMessage();    // Message
    $code    = $e->getCode();       // Error code (-1 if not available)
    $status  = $e->getStatusCode(); // HTTP status code

} catch (CURLException $e) {

    // cURL communication failed.
    $message = $e->getMessage();    // Message    (equivalent to curl_error())
    $code    = $e->getCode();       // Error code (equivalent to curl_errno())

}
```

or

```
try {

    // do stuff here
    $client->get(...);
    $client->post(...);

} catch (\RuntimeException $e) {

    // Something failed.
    $message = $e->getMessage();

}
```

### Avoiding SSL errors due to the old libcurl version

[](#avoiding-ssl-errors-due-to-the-old-libcurl-version)

If you encountered `SSL certificate problem` error...

1. Download the latest `cacert.pem` from official libcurl site.

2. Please choose either of the following solutions.

#### 2-A: Configure globally

[](#2-a-configure-globally)

Specify the path as **`curl.cainfo`** in your `php.ini`.

```
curl.cainfo="C:\foo\bar\baz\cacert.pem"
```

DO NOT forget restarting Apache.

#### 2-B: Configure locally

[](#2-b-configure-locally)

Specify the path as **`CURLOPT_CAINFO`**. Using the magic constant `__DIR__` is recommended.

```
$client = new Client(['CK', 'CS', 'AT', 'ATS'], [CURLOPT_CAINFO => __DIR__ . '/cacert.pem']);
```

or

```
$client = new Client(['CK', 'CS', 'AT', 'ATS']);
$client = $client->withOptions([CURLOPT_CAINFO => __DIR__ . '/cacert.pem']);
```

Details
-------

[](#details)

Read interfaces.

- [Client](src/ClientInterface.php)
- [Response](src/ResponseInterface.php)
- [Media](src/MediaInterface.php)
- [HttpException](src/HttpExceptionInterface.php)

Todos
-----

[](#todos)

- Documentation
- Improving codes

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 97% 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 ~94 days

Recently: every ~118 days

Total

6

Last Release

3073d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2c31c65dbc5a041c4fa8037bd048edd3aa4a912211fc587b11804396b092d222?d=identicon)[kawakami-o3](/maintainers/kawakami-o3)

---

Top Contributors

[![mpyw](https://avatars.githubusercontent.com/u/1351893?v=4)](https://github.com/mpyw "mpyw (256 commits)")[![kawakami-o3-2nd](https://avatars.githubusercontent.com/u/83420975?v=4)](https://github.com/kawakami-o3-2nd "kawakami-o3-2nd (4 commits)")[![yarnaimo](https://avatars.githubusercontent.com/u/9738886?v=4)](https://github.com/yarnaimo "yarnaimo (2 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![suzutan](https://avatars.githubusercontent.com/u/6679870?v=4)](https://github.com/suzutan "suzutan (1 commits)")

---

Tags

asyncasynchronousapiimagestreamingvideooauthtwitteruploadparalell

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/kawakami-o3-cowitter/health.svg)

```
[![Health](https://phpackages.com/badges/kawakami-o3-cowitter/health.svg)](https://phpackages.com/packages/kawakami-o3-cowitter)
```

###  Alternatives

[hybridauth/hybridauth

PHP Social Authentication Library

3.4k8.5M94](/packages/hybridauth-hybridauth)[mollie/oauth2-mollie-php

Mollie Provider for OAuth 2.0 Client

251.7M1](/packages/mollie-oauth2-mollie-php)

PHPackages © 2026

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