PHPackages                             coderjerk/bird-elephant - 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. [API Development](/categories/api)
4. /
5. coderjerk/bird-elephant

ActiveLibrary[API Development](/categories/api)

coderjerk/bird-elephant
=======================

A simple library to request data from the Twitter APIv2 endpoints

v0.7.1(2y ago)95137.6k—3.8%26[5 issues](https://github.com/danieldevine/bird-elephant/issues)[2 PRs](https://github.com/danieldevine/bird-elephant/pulls)2MITPHP

Since Nov 4Pushed 2y ago3 watchersCompare

[ Source](https://github.com/danieldevine/bird-elephant)[ Packagist](https://packagist.org/packages/coderjerk/bird-elephant)[ GitHub Sponsors](https://github.com/danieldevine)[ RSS](/packages/coderjerk-bird-elephant/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (21)Used By (2)

[![Bird Elephant](https://camo.githubusercontent.com/36ab4c88bc74100ca842dfcc3051d5b67a30a239b1fe665bbd1637ff62aa4a6d/68747470733a2f2f62697264656c657068616e742e636f6d2f6c6f676f2d626972642d656c657068616e742e737667)](https://camo.githubusercontent.com/36ab4c88bc74100ca842dfcc3051d5b67a30a239b1fe665bbd1637ff62aa4a6d/68747470733a2f2f62697264656c657068616e742e636f6d2f6c6f676f2d626972642d656c657068616e742e737667)

[![Latest Packagist Version](https://camo.githubusercontent.com/87bf89603e74ecb27761d6607304fbc810aa980519df29548de0062b4c773bf4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f6465726a65726b2f626972642d656c657068616e743f6c6f676f3d676974687562266c6f676f436f6c6f723d7768697465267374796c653d666c61742d737175617265)](https://packagist.org/packages/coderjerk/bird-elephant) [![Total Downloads](https://camo.githubusercontent.com/b891f8711b1e1efe0523e3979c7bded675f0c61d37eec0bca5bd2ff1d2132f14/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f6465726a65726b2f626972642d656c657068616e742e7376673f6c6f676f3d676974687562266c6f676f436f6c6f723d7768697465267374796c653d666c61742d737175617265)](https://packagist.org/packages/coderjerk/bird-elephant)

[![Minimum PHP Version](https://camo.githubusercontent.com/183804d09fec16ca7b6209b007250b7d8db1b915042feb093a9f20e6e1f25359/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e312d3838393242462e737667)](https://php.net/) [![twitter](https://camo.githubusercontent.com/bbc8d4207359eb9498eb9dee46cf6a38d1a3f652b28088662848a346949ba79b/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f666f6c6c6f772f636f6465726a65726b3f7374796c653d736f6369616c)](https://twitter.com/coderjerk)

### Connect to Twitter API v2 endpoints in PHP.

[](#connect-to-twitter-api-v2-endpoints-in-php)

This package provides a number of useful ways to interact with the Twitter Rest API v2 endpoints in PHP. It provides a clean and easy to understand set of methods and classes to send tweets, manage users, lookup data, and everything else that the Twitter API v2 provides, from within your app or site.

[Full documentation and examples on birdelephant.com](https://birdelephant.com)

Getting Started
---------------

[](#getting-started)

To use the Twitter API v2, and consequently this package, you must have an approved developer account and have activated the new developer portal.

Learn more about getting access to the Twitter API v2 endpoints:

[Twitter Api Getting Started Docs](https://developer.twitter.com/en/docs/twitter-api/getting-started/guide)

Install
-------

[](#install)

Install via composer.

```
composer require coderjerk/bird-elephant
```

Authentication
--------------

[](#authentication)

You will need to generate your credentials when creating your App in Developer Portal.

Follow the Twitter developer documentation above on how to do this. Make sure to grant your app the correct permissions, and enable 3 legged OAuth if you need it.

Pass the credentials as a key value array as follows:

```
$credentials = array(
    //these are values that you can obtain from developer portal:
    'consumer_key' => xxxxxx, // identifies your app, always needed
    'consumer_secret' => xxxxxx, // app secret, always needed
    'bearer_token' => xxxxxx, // OAuth 2.0 Bearer Token requests

    //this is a value created duting an OAuth 2.0 with PKCE authentication flow:
    'auth_token' => xxxxxx // OAuth 2.0 auth token

    //these are values created during an OAuth 1.0a authentication flow to act ob behalf of other users, but these can also be obtained for your app from the developer portal in order to act on behalf of your app.
    'token_identifier' => xxxxxx, // OAuth 1.0a User Context requests
    'token_secret' => xxxxxx, // OAuth 1.0a User Context requests
);

$twitter = new BirdElephant($credentials);
```

[Twitter Developer Authentication docs](https://developer.twitter.com/en/docs/authentication/overview)

OAuth 2.0 Bearer token auth is the most straightforward, but will limit you to certain endpoints.

Of course, in both possible user context auth flows, you will need to pass the authenticated user's credentials as token\_identifier and token\_secret for OAuth 1.0a *or* 'auth\_token' for OAuth 2.0.

OAuth 1.0a is supported, but it would be wise for new apps to prefer OAuth 2.0 with PKCE as certain newer endpoints only support this form of authentication, and it is posible that Twitter might drop support for it in the future.

OAuth 1.0a is needed to perform media uploads - the only Api v1.1 endpoint supported by BirdElephant as a v2 replacement doesn't exist yet.

You can look at [index.php](/index.php) and [authenticate.php](/authenticate.php) for an example of how a simple OAuth 2.0 with PKCE flow might work in practice. Use a dedicated oAuth library for this - in the example I use [smolblog/oauth2-twitter](https://github.com/smolblog/oauth2-twitter), which does the job well.

Remember to include the necessary scopes when using OAuth 2.0 with PKCE - full list here:

**Protect your credentials carefully and never commit them to your repository**. I'd recommend using a .env file to manage your credentials, you can copy the contents of .env.example to .env in your project and populate with your own credentials if you wish: [how to use it here](https://github.com/vlucas/phpdotenv)

Documentation
-------------

[](#documentation)

[Documentation and examples for all available Bird Elephant methods can be found here.](https://birdelephant.com)

Quick Examples
--------------

[](#quick-examples)

The package provides a number of different ways of interacting with the Twitter API. The recommended way is by using the simple helper methods, but a utility method is available and direct access to many of the underlying classes is also possible. If you wish to interact with the underlying classes, read the documentation in the code.

```
use Coderjerk\BirdElephant\BirdElephant;

//your credentials, should be passed in via $_ENV or similar, don't hardcode.
$credentials = array(
    'consumer_key' => xxxxxx,
    'consumer_secret' => xxxxxx,
    'bearer_token' => xxxxxx,
    // if using oAuth 2.0 with PKCE
    'auth_token' => xxxxxx // OAuth 2.0 auth token
    //if using oAuth 1.0a
    'token_identifier' => xxxxxx,
    'token_secret' => xxxxxx,
);

//instantiate the object
$twitter = new BirdElephant($credentials);

//get a user's followers using the handy helper methods
$followers = $twitter->user('coderjerk')->followers();

//pass your query params to the methods directly
$following = $twitter->user('coderjerk')->following([
    'max_results' => 20,
    'user.fields' => 'profile_image_url'
]);

//tweet something
$tweet = (new \Coderjerk\BirdElephant\Compose\Tweet)->text(".@coderjerk is so cool");

$twitter->tweets()->tweet($tweet);

// You can also use the sub classes / methods directly if you like:
$user = new UserLookup($credentials);
$user = $user->getSingleUserByID('2244994945', null);
```

Reference
---------

[](#reference)

- [Bird Elephant Reference](https://birdelephant.com)
- [Twitter API reference index](https://developer.twitter.com/en/docs/api-reference-index)

Notes
-----

[](#notes)

This is an unofficial tool written by [me](https://github.com/danieldevine) in my spare time and is not affiliated with Twitter.

This package does not support Twitter API v1.1 (with the exception of media uploads).

Sponsored By
------------

[](#sponsored-by)

[![Hype Machine](/img/sponsors/hype_machine.png "Hype Machine")](https://hypem.com/)

Thanks to [Hype Machine](https://hypem.com/) for sponsoring the project.

Sponsor
-------

[](#sponsor)

If you or your company find this library useful show your love by throwing me a few euros and I'll give you a shout out on here and on the [project website](https://birdelephant.com/)

[Sponsor Development](https://github.com/sponsors/danieldevine)

Contributing
------------

[](#contributing)

Fork/download the code and run

`composer install`

copy `.env.example` to `.env` and add your credentials for testing.

To run tests

`./vendor/bin/phpunit`

Issues, pull requests and other contributions most welcome. Please use the issue template provided.

You can [look at the project board for upcoming features](https://github.com/danieldevine/bird-elephant/projects/1) if you want to pitch in :)

[Where we go from here - the future of the project in light of changes to the API](https://coderjerk.com/gifting-labour-to-big-business/)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.8% 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 ~49 days

Recently: every ~151 days

Total

18

Last Release

825d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/57a1b0f82fadf970d1068cd30fd72f6e85ea2abe3fc9e3ff082b32381e42db8f?d=identicon)[Coderjerk](/maintainers/Coderjerk)

---

Top Contributors

[![danieldevine](https://avatars.githubusercontent.com/u/5939939?v=4)](https://github.com/danieldevine "danieldevine (179 commits)")[![shaneiseminger](https://avatars.githubusercontent.com/u/843313?v=4)](https://github.com/shaneiseminger "shaneiseminger (2 commits)")[![developersteve](https://avatars.githubusercontent.com/u/1458790?v=4)](https://github.com/developersteve "developersteve (1 commits)")[![SuperAzeem](https://avatars.githubusercontent.com/u/4667434?v=4)](https://github.com/SuperAzeem "SuperAzeem (1 commits)")

---

Tags

phptwittertwitter-apitwitter-api-v2

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/coderjerk-bird-elephant/health.svg)

```
[![Health](https://phpackages.com/badges/coderjerk-bird-elephant/health.svg)](https://phpackages.com/packages/coderjerk-bird-elephant)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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