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

ActiveLibrary[API Development](/categories/api)

sursolar/twitter
================

Twitter API for Laravel

2.2.2(9y ago)232MITPHPPHP &gt;=5.5.0

Since Jun 27Pushed 6y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (33)Used By (0)

Twitter
=======

[](#twitter)

Twitter API for Laravel 4/5

You need to create an application and create your access token in the [Application Management](https://apps.twitter.com/).

[![Build Status](https://camo.githubusercontent.com/9b4428e685a469a47b60595b2a5498c2f3348a5032aec760970d89b5dfbbd6cb/68747470733a2f2f7472617669732d63692e6f72672f7468756a6f686e2f747769747465722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/thujohn/twitter)

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

[](#installation)

Add `thujohn/twitter` to `composer.json`.

```
"thujohn/twitter": "~2.0"

```

Run `composer update` to pull down the latest version of Twitter.

Or run

```
composer require thujohn/twitter

```

Now open up `/config/app.php` and add the service provider to your `providers` array.

```
'providers' => [
	'Thujohn\Twitter\TwitterServiceProvider',
]
```

Now add the alias.

```
'aliases' => [
	'Twitter' => 'Thujohn\Twitter\Facades\Twitter',
]
```

Upgrading from 1.x.x
--------------------

[](#upgrading-from-1xx)

The package now requires PHP &gt;= 5.4.0

Facade has changed (Thujohn\\Twitter\\Facades\\Twitter)

Config file has been updated (debug, UPLOAD\_URL, ACCESS\_TOKEN\_URL, REQUEST\_TOKEN\_URL)

set\_new\_config() has been renamed reconfig()

Configuration (Laravel 4)
-------------------------

[](#configuration-laravel-4)

Run `php artisan config:publish thujohn/twitter` and modify the config file with your own informations.

```
/app/config/packages/thujohn/twitter/config.php

```

Also, make sure to remove the env in the config file and replace it with your information.

Configuration (Laravel 5)
-------------------------

[](#configuration-laravel-5)

Run `php artisan vendor:publish --provider="Thujohn\Twitter\TwitterServiceProvider"` and modify the config file with your own information.

```
/config/ttwitter.php

```

With Laravel 5, it's simple to edit the config.php file - in fact you don't even need to touch it! Just add the following to your .env file and you'll be on your way:

```
TWITTER_CONSUMER_KEY =
TWITTER_CONSUMER_SECRET =
TWITTER_ACCESS_TOKEN =
TWITTER_ACCESS_TOKEN_SECRET =

```

Special parameter
-----------------

[](#special-parameter)

```
format : object|json|array (default:object)

```

Functions
---------

[](#functions)

Linkify : Transforms URLs, @usernames, hashtags into links. The type of $tweet can be object, array or text. By sending an object or an array the method will expand links (t.co) too.

```
Twitter::linkify($tweet);
```

Ago : Converts date into difference (2 hours ago)

```
Twitter::ago($timestamp);
```

LinkUser : Generates a link to a specific user, by their user object (such as $tweet-&gt;user), or id/string.

```
Twitter::linkUser($user);
```

LinkTweet : Generates a link to a specific tweet.

```
Twitter::linkTweet($tweet);
```

Examples
--------

[](#examples)

Returns a collection of the most recent Tweets posted by the user indicated by the screen\_name or user\_id parameters.

```
Route::get('/', function()
{
	return Twitter::getUserTimeline(['screen_name' => 'thujohn', 'count' => 20, 'format' => 'json']);
});
```

Returns a collection of the most recent Tweets and retweets posted by the authenticating user and the users they follow.

```
Route::get('/', function()
{
	return Twitter::getHomeTimeline(['count' => 20, 'format' => 'json']);
});
```

Returns the X most recent mentions (tweets containing a users's @screen\_name) for the authenticating user.

```
Route::get('/', function()
{
	return Twitter::getMentionsTimeline(['count' => 20, 'format' => 'json']);
});
```

Updates the authenticating user's current status, also known as tweeting.

```
Route::get('/', function()
{
	return Twitter::postTweet(['status' => 'Laravel is beautiful', 'format' => 'json']);
});
```

Updates the authenticating user's current status with media.

```
Route::get('/', function()
{
	$uploaded_media = Twitter::uploadMedia(['media' => File::get(public_path('filename.jpg'))]);
	return Twitter::postTweet(['status' => 'Laravel is beautiful', 'media_ids' => $uploaded_media->media_id_string]);
});
```

Get User Credentials with email.

```
$credentials = Twitter::getCredentials([
    'include_email' => 'true',
]);

```

> In the above, you need to pass true as a string, not as a boolean. The boolean will get converted to `1` which Twitter ignores.

> This also is assuming you have your permissions setup correctly with Twitter. You have to choose 'Get user email' when you set up your Twitter app, passing the value alone will not be enough.

Sign in with twitter

```
Route::get('twitter/login', ['as' => 'twitter.login', function(){
	// your SIGN IN WITH TWITTER  button should point to this route
	$sign_in_twitter = true;
	$force_login = false;

	// Make sure we make this request w/o tokens, overwrite the default values in case of login.
	Twitter::reconfig(['token' => '', 'secret' => '']);
	$token = Twitter::getRequestToken(route('twitter.callback'));

	if (isset($token['oauth_token_secret']))
	{
		$url = Twitter::getAuthorizeURL($token, $sign_in_twitter, $force_login);

		Session::put('oauth_state', 'start');
		Session::put('oauth_request_token', $token['oauth_token']);
		Session::put('oauth_request_token_secret', $token['oauth_token_secret']);

		return Redirect::to($url);
	}

	return Redirect::route('twitter.error');
}]);

Route::get('twitter/callback', ['as' => 'twitter.callback', function() {
	// You should set this route on your Twitter Application settings as the callback
	// https://apps.twitter.com/app/YOUR-APP-ID/settings
	if (Session::has('oauth_request_token'))
	{
		$request_token = [
			'token'  => Session::get('oauth_request_token'),
			'secret' => Session::get('oauth_request_token_secret'),
		];

		Twitter::reconfig($request_token);

		$oauth_verifier = false;

		if (Input::has('oauth_verifier'))
		{
			$oauth_verifier = Input::get('oauth_verifier');
		}

		// getAccessToken() will reset the token for you
		$token = Twitter::getAccessToken($oauth_verifier);

		if (!isset($token['oauth_token_secret']))
		{
			return Redirect::route('twitter.login')->with('flash_error', 'We could not log you in on Twitter.');
		}

		$credentials = Twitter::getCredentials();

		if (is_object($credentials) && !isset($credentials->error))
		{
			// $credentials contains the Twitter user object with all the info about the user.
			// Add here your own user logic, store profiles, create new users on your tables...you name it!
			// Typically you'll want to store at least, user id, name and access tokens
			// if you want to be able to call the API on behalf of your users.

			// This is also the moment to log in your users if you're using Laravel's Auth class
			// Auth::login($user) should do the trick.

			Session::put('access_token', $token);

			return Redirect::to('/')->with('flash_notice', 'Congrats! You\'ve successfully signed in!');
		}

		return Redirect::route('twitter.error')->with('flash_error', 'Crab! Something went wrong while signing you up!');
	}
}]);

Route::get('twitter/error', ['as' => 'twitter.error', function(){
	// Something went wrong, add your own error handling here
}]);

Route::get('twitter/logout', ['as' => 'twitter.logout', function(){
	Session::forget('access_token');
	return Redirect::to('/')->with('flash_notice', 'You\'ve successfully logged out!');
}]);
```

Debug
-----

[](#debug)

First activate debug in the config file.

Then you can access the logs() method.

```
try
{
	$response = Twitter::getUserTimeline(['count' => 20, 'format' => 'array']);
}
catch (Exception $e)
{
	dd(Twitter::logs());
}

dd($response);
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 64.5% 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 ~43 days

Recently: every ~83 days

Total

32

Last Release

3356d ago

Major Versions

1.2.0 → 2.0.02015-03-22

PHP version history (3 changes)1.0.0PHP &gt;=5.3.0

2.0.0PHP &gt;=5.4.0

2.2.2PHP &gt;=5.5.0

### Community

Maintainers

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

---

Top Contributors

[![thujohn](https://avatars.githubusercontent.com/u/580699?v=4)](https://github.com/thujohn "thujohn (78 commits)")[![MauMaGau](https://avatars.githubusercontent.com/u/896962?v=4)](https://github.com/MauMaGau "MauMaGau (7 commits)")[![j3j5](https://avatars.githubusercontent.com/u/1239921?v=4)](https://github.com/j3j5 "j3j5 (6 commits)")[![sursolar](https://avatars.githubusercontent.com/u/20163188?v=4)](https://github.com/sursolar "sursolar (3 commits)")[![mateusrevoredo](https://avatars.githubusercontent.com/u/1175432?v=4)](https://github.com/mateusrevoredo "mateusrevoredo (3 commits)")[![clarkf](https://avatars.githubusercontent.com/u/439978?v=4)](https://github.com/clarkf "clarkf (2 commits)")[![marcorivm](https://avatars.githubusercontent.com/u/1222598?v=4)](https://github.com/marcorivm "marcorivm (2 commits)")[![djug](https://avatars.githubusercontent.com/u/1019873?v=4)](https://github.com/djug "djug (2 commits)")[![Craytor](https://avatars.githubusercontent.com/u/3680866?v=4)](https://github.com/Craytor "Craytor (2 commits)")[![nivv](https://avatars.githubusercontent.com/u/4033930?v=4)](https://github.com/nivv "nivv (2 commits)")[![nWidart](https://avatars.githubusercontent.com/u/882397?v=4)](https://github.com/nWidart "nWidart (2 commits)")[![ebisbe](https://avatars.githubusercontent.com/u/6747962?v=4)](https://github.com/ebisbe "ebisbe (2 commits)")[![silentFred](https://avatars.githubusercontent.com/u/1550207?v=4)](https://github.com/silentFred "silentFred (2 commits)")[![trapvincenzo](https://avatars.githubusercontent.com/u/5497475?v=4)](https://github.com/trapvincenzo "trapvincenzo (1 commits)")[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (1 commits)")[![clemblanco](https://avatars.githubusercontent.com/u/668419?v=4)](https://github.com/clemblanco "clemblanco (1 commits)")[![leewillis77](https://avatars.githubusercontent.com/u/1097338?v=4)](https://github.com/leewillis77 "leewillis77 (1 commits)")[![mikevrind](https://avatars.githubusercontent.com/u/594341?v=4)](https://github.com/mikevrind "mikevrind (1 commits)")[![nhalloran](https://avatars.githubusercontent.com/u/1732298?v=4)](https://github.com/nhalloran "nhalloran (1 commits)")[![RobertDeniszczyc](https://avatars.githubusercontent.com/u/4614790?v=4)](https://github.com/RobertDeniszczyc "RobertDeniszczyc (1 commits)")

---

Tags

laraveltwitterlaravel5laravel4

### Embed Badge

![Health badge](/badges/sursolar-twitter/health.svg)

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

###  Alternatives

[thujohn/analytics

Google Analytics for Laravel 4

113108.7k1](/packages/thujohn-analytics)[scottybo/laravel-google-my-business

A package for Laravel which implements the Google My Business API

3360.3k](/packages/scottybo-laravel-google-my-business)[travoltron/plaid

Laravel specific wrapper for Plaid. Bankdata for developers.

274.8k](/packages/travoltron-plaid)[edujugon/social-auto-post

PHP and Laravel 5 Package to post on Twitter

135.9k](/packages/edujugon-social-auto-post)

PHPackages © 2026

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