PHPackages                             laravel-notification-channels/twitter - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. laravel-notification-channels/twitter

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

laravel-notification-channels/twitter
=====================================

This package makes it easy to send notifications via Twitter with Laravel

v9.1.0(4mo ago)176232.2k—1.4%43[7 issues](https://github.com/laravel-notification-channels/twitter/issues)1MITPHPPHP ^8.4CI passing

Since Aug 21Pushed 3w ago9 watchersCompare

[ Source](https://github.com/laravel-notification-channels/twitter)[ Packagist](https://packagist.org/packages/laravel-notification-channels/twitter)[ Docs](https://github.com/laravel-notification-channels/twitter)[ RSS](/packages/laravel-notification-channels-twitter/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (16)Versions (51)Used By (1)

[![image](https://user-images.githubusercontent.com/1394539/224646721-20af92f0-2a46-45c0-9700-cfdbe9edf76c.png)](https://user-images.githubusercontent.com/1394539/224646721-20af92f0-2a46-45c0-9700-cfdbe9edf76c.png)

Twitter notification channel for Laravel
========================================

[](#twitter-notification-channel-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3b51c856ec0700c209da5b61b3564694e97d772cbd871d03f9b9f9df65de660e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61726176656c2d6e6f74696669636174696f6e2d6368616e6e656c732f747769747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laravel-notification-channels/twitter)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![StyleCI](https://camo.githubusercontent.com/fae1d9b40eb3780048636b7ac5b6bb8b3013e25ee5f853e30c9f1bb8774f768a/68747470733a2f2f7374796c6563692e696f2f7265706f732f36353834373338362f736869656c64)](https://styleci.io/repos/65847386)[![Quality Score](https://camo.githubusercontent.com/34b13683bb3894f624d0bfa5ea49a19f0014daa50c504c8e63f27240e91de363/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6c61726176656c2d6e6f74696669636174696f6e2d6368616e6e656c732f747769747465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/laravel-notification-channels/twitter)[![Code Coverage](https://camo.githubusercontent.com/ccb090a66331ed57083ca48b9e37584a94582b5530144671a484a9b7421891d5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6c61726176656c2d6e6f74696669636174696f6e2d6368616e6e656c732f747769747465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/laravel-notification-channels/twitter/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/c559b8579ed4067415fe6a3adbbee1b1710fa3b25c0e19bf06bcc77824ba8a06/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61726176656c2d6e6f74696669636174696f6e2d6368616e6e656c732f747769747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laravel-notification-channels/twitter)

This package makes it easy to send Laravel notifications using [Twitter](https://dev.twitter.com/rest/public). (Laravel 8+)

PS: v8 now uses the new Twitter API V2. Please read the upgrade guide for your app [here](https://developer.twitter.com/en/docs/twitter-api/migrate/overview).

Contents
--------

[](#contents)

- [About](#about)
- [Installation](#installation)
- [Setting up the Twitter service](#setting-up-the-twitter-service)
- [Usage](#usage)
    - [Publish a Twitter status update](#publish-a-twitter-status-update)
    - [Publish Twitter status update with images](#publish-twitter-status-update-with-images)
    - [Publish Twitter status update with videos](#publish-twitter-status-update-with-videos)
    - [Publish Twitter status update with both images and videos](#publish-twitter-status-update-with-both-images-and-videos)
    - [Send a direct message](#send-a-direct-message)
- [Handle multiple Twitter Accounts](#handle-multiple-twitter-accounts)
- [Changelog](#changelog)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

About
-----

[](#about)

This package is part of the [Laravel Notification Channels](http://laravel-notification-channels.com/) project. It provides additional Laravel Notification channels to the ones given by [Laravel](https://laravel.com/docs/master/notifications) itself.

The Twitter channel makes it possible to send out Laravel notifications as a `Twitter tweet` (post on the timeline) or as a `direct message`.

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

[](#installation)

If you prefer a video, there is also [an introduction video](https://christoph-rumpel.com/2018/11/sending-laravel-notifications-via-twitter) available for you. If not, just read on.

You can install this package via composer:

```
composer require laravel-notification-channels/twitter
```

The service provider gets loaded automatically.

### Twitter App &amp; Credentials

[](#twitter-app--credentials)

You will need to [create](https://developer.twitter.com/apps/) a Twitter app to use this channel. Within this app, you will find the `keys and access tokens`.

Your Twitter app `must be within a project`. Also, make sure to activate the `user authentication settings`:

[![image](https://private-user-images.githubusercontent.com/1394539/253810580-9be260ba-d8db-4af1-be58-9e4ce3b0176d.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODI5NTM5ODIsIm5iZiI6MTc4Mjk1MzY4MiwicGF0aCI6Ii8xMzk0NTM5LzI1MzgxMDU4MC05YmUyNjBiYS1kOGRiLTRhZjEtYmU1OC05ZTRjZTNiMDE3NmQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDcwMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjA3MDJUMDA1NDQyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YzlmYzdjYzVmOTExMWUyMzJlZmZhZDNmNGJkMjAxNDExYmRkZjc3YTVmZTBkYjQ3MGQzNjc0MjhiNjZmMTcxMCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmcmVzcG9uc2UtY29udGVudC10eXBlPWltYWdlJTJGcG5nIn0.Z-u0aYJ5k9ww8d2qLQ2xCsdgTqSWWlVvGk_VPU4z-OA)](https://private-user-images.githubusercontent.com/1394539/253810580-9be260ba-d8db-4af1-be58-9e4ce3b0176d.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODI5NTM5ODIsIm5iZiI6MTc4Mjk1MzY4MiwicGF0aCI6Ii8xMzk0NTM5LzI1MzgxMDU4MC05YmUyNjBiYS1kOGRiLTRhZjEtYmU1OC05ZTRjZTNiMDE3NmQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDcwMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjA3MDJUMDA1NDQyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YzlmYzdjYzVmOTExMWUyMzJlZmZhZDNmNGJkMjAxNDExYmRkZjc3YTVmZTBkYjQ3MGQzNjc0MjhiNjZmMTcxMCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmcmVzcG9uc2UtY29udGVudC10eXBlPWltYWdlJTJGcG5nIn0.Z-u0aYJ5k9ww8d2qLQ2xCsdgTqSWWlVvGk_VPU4z-OA)After that, you have to regenerate your access token and secret. If done correctly, you should see the right permissions for your access tokens:

[![image](https://private-user-images.githubusercontent.com/1394539/253810284-6ee5fc99-0373-4ebb-b8c5-4c84a82632df.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODI5NTM5ODIsIm5iZiI6MTc4Mjk1MzY4MiwicGF0aCI6Ii8xMzk0NTM5LzI1MzgxMDI4NC02ZWU1ZmM5OS0wMzczLTRlYmItYjhjNS00Yzg0YTgyNjMyZGYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDcwMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjA3MDJUMDA1NDQyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZGNkMGFhNTUzMmVlZjI3ZGI3OGE5MzNmNmE2MGNkYmI0MDJjNWRhNWZiYTg4NDIyNDUwNzgzZTFjMzZmYjkzMSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmcmVzcG9uc2UtY29udGVudC10eXBlPWltYWdlJTJGcG5nIn0.aAbvwQQi8QO7UOrs5dra7bSP-XQvjD0t2-_c1QN36b0)](https://private-user-images.githubusercontent.com/1394539/253810284-6ee5fc99-0373-4ebb-b8c5-4c84a82632df.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODI5NTM5ODIsIm5iZiI6MTc4Mjk1MzY4MiwicGF0aCI6Ii8xMzk0NTM5LzI1MzgxMDI4NC02ZWU1ZmM5OS0wMzczLTRlYmItYjhjNS00Yzg0YTgyNjMyZGYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDcwMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjA3MDJUMDA1NDQyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZGNkMGFhNTUzMmVlZjI3ZGI3OGE5MzNmNmE2MGNkYmI0MDJjNWRhNWZiYTg4NDIyNDUwNzgzZTFjMzZmYjkzMSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmcmVzcG9uc2UtY29udGVudC10eXBlPWltYWdlJTJGcG5nIn0.aAbvwQQi8QO7UOrs5dra7bSP-XQvjD0t2-_c1QN36b0)Make sure to copy the right credentials and place them inside your `.env` file.

```
TWITTER_CONSUMER_KEY=your-consumer-key
TWITTER_CONSUMER_SECRET=your-consumer-secret
TWITTER_ACCESS_TOKEN=your-accesss_token
TWITTER_ACCESS_SECRET=your-access-token-secret
```

[![image](https://private-user-images.githubusercontent.com/1394539/253810329-7e68325d-0255-4f66-a310-86f3277f52a7.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODI5NTM5ODIsIm5iZiI6MTc4Mjk1MzY4MiwicGF0aCI6Ii8xMzk0NTM5LzI1MzgxMDMyOS03ZTY4MzI1ZC0wMjU1LTRmNjYtYTMxMC04NmYzMjc3ZjUyYTcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDcwMi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JDThk0KgPFLWtVpQJkUj4PUneOiYxNlDAXYz2msFBA4)To load them, add this to your `config/services.php` file:

```
...
'twitter' => [
    'consumer_key'    => env('TWITTER_CONSUMER_KEY'),
    'consumer_secret' => env('TWITTER_CONSUMER_SECRET'),
    'access_token'    => env('TWITTER_ACCESS_TOKEN'),
    'access_secret'   => env('TWITTER_ACCESS_SECRET')
]
...
```

Usage
-----

[](#usage)

To use this package, you need to create a notification class, like `NewsWasPublished` from the example below, in your Laravel application. Make sure to check out [Laravel's documentation](https://laravel.com/docs/master/notifications) for this process.

### Publish a Twitter status update

[](#publish-a-twitter-status-update)

```
