PHPackages                             fetchwitter/fetchwitter - 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. fetchwitter/fetchwitter

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

fetchwitter/fetchwitter
=======================

PHP framework to fetch tweets from Twitter API v1.1 using OAuth authentication/authorization

1.0.9(10y ago)15932[5 issues](https://github.com/jabranr/Fetchwitter/issues)[1 PRs](https://github.com/jabranr/Fetchwitter/pulls)MIT LicensePHPPHP &gt;=5.3.0

Since Jul 7Pushed 10y ago3 watchersCompare

[ Source](https://github.com/jabranr/Fetchwitter)[ Packagist](https://packagist.org/packages/fetchwitter/fetchwitter)[ Docs](http://git.io/fetchwitter)[ RSS](/packages/fetchwitter-fetchwitter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (7)Used By (0)

Fetchwitter [![Build Status](https://camo.githubusercontent.com/b488e821d28bdb665c3872f51d637a77d2e71746e40b1628b63f7ae3561e772b/68747470733a2f2f7472617669732d63692e6f72672f6a616272616e722f66657463687769747465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jabranr/fetchwitter) [![Latest Stable Version](https://camo.githubusercontent.com/50259b2dee1f579f647cf6893a8b2bc28fbd5a7edc7ae22fd4f31c88867715b4/68747470733a2f2f706f7365722e707567782e6f72672f66657463687769747465722f66657463687769747465722f762f737461626c652e737667)](https://packagist.org/packages/fetchwitter/fetchwitter) [![Total Downloads](https://camo.githubusercontent.com/2981e63e9f8f57547a4fdaa4afbc952e98eca4642bb8b2aca8cd54e1f3aaf1f4/68747470733a2f2f706f7365722e707567782e6f72672f66657463687769747465722f66657463687769747465722f646f776e6c6f6164732e737667)](https://packagist.org/packages/fetchwitter/fetchwitter) [![Analytics](https://camo.githubusercontent.com/f87d99b757714bdad7f7b451c618227095e16d46ce6d0284360fd0cbb056a18a/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d35303638383835312d312f6665746368776974746572)](https://github.com/igrigorik/ga-beacon)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#fetchwitter----)

PHP library to fetch tweets from Twitter API v1.1 using OAuth authentication/authorization. Fetchwitter provides easy to use methods for basic functionality such as tweets or hashtag search, or fetch a user timeline feed. All you need are Twitter app key and secret to get you going.

> Note: The authentication flow uses Twitter’s App-Only Authentication.

Install
-------

[](#install)

Fetchwitter can be installed using one of following methods:

- [Download latest release](https://github.com/jabranr/Fetchwitter/releases/latest)

#### Using Composer (Recommended)

[](#using-composer-recommended)

Add as dependency into your `composer.json` file.

```
{
	"require": {
		"fetchwitter/fetchwitter": ">=1.0.8"
	}
}
```

Use [Composer](http://getcomposer.org) to install.

```
$ composer install
```

Require/include the file into your project

```
require 'path/to/vendor/fetchwitter/autoload.php'
```

Basic Example
-------------

[](#basic-example)

The instance initialization automatically fetches the access token using OAuth flow and makes it available to the class. An existing access token can also be set manually as follow.

The configuration arguments can be passed as string, indexed array or associative array. Basically 2 arguments are required that are API Key and Secret. If you already have an access token you can optionally pass it as third parameter to bypass the automatic OAuth flow and make API calls using your access token. Here is a very basic example to start with.

Pass arguments as associative array:

```
$config = array(
	'api_key' => 'API_KEY',
	'api_secret' => 'API_SECRET',
	'access_token' => 'ACCESS_TOKEN', // optional
);

try {
	$fw = new Fetchwitter($config);
}
catch(Exception $e) {
	echo $e->getMessage();
}
```

or pass arguments as indexed array:

```
$config = array( 'API_KEY', 'API_SECRET', 'ACCESS_TOKEN' /* optional */ );

try {
	$fw = new Fetchwitter($config);
}
catch(Exception $e) {
	echo $e->getMessage();
}
```

or pass arguments as strings:

```
try {
	$fw = new Fetchwitter( 'API_KEY', 'API_SECRET', 'ACCESS_TOKEN' /* optional */ );
}
catch(Exception $e) {
	echo $e->getMessage();
}
```

### Configuration &amp; Initialization

[](#configuration--initialization)

- Register a new app at [Twitter Application Manager](https://apps.twitter.com) and get API key and secret.
- Initialize a new instance of Fetchwitter as explained above.
- Make API requests as exampled below:

Make any GET request i.e. fetch user timeline

```
$fw->get('statuses/user_timeline', array(
	'count' => 2,
	'screen_name' => 'jabranr'
	)
);
```

Search tweets with a hashtag

```
$fw->get('search/tweets', array(
	'count' => 2,
	'q' => '#TwitterAPI',
	'result_type' => 'recent'
	)
);
```

Once a valid instance of Fetchwitter is created, it automatically goes through an [App-Only Authentication](https://dev.twitter.com/docs/auth/application-only-auth) and gets a valid `access_token` from Twitter API or returns appropriate error message in case of failure.

> The method will throw an Exception in case of any missing parameters or returns error message from API in JSON format otherwise.

Following methods are available for a valid and successfully established connection with API.

### Helper method `toTweet()`

[](#helper-method-totweet)

Use `toTweet( $text )` method to convert the static Tweet to formatted Tweet with Mentions, Hashtags and Links properly linked. The method takes the Tweet in string format as parameter and returns a formatted Tweet.

**Use:**

```
$tweet = $fetchwitter->toTweet( string $tweet );
```

**Example:**

**Static Tweet as it comes from the API feed:**

This is a #test tweet by @jabranr to confirm methods from #Fetchwitter. More at

**Formatted Tweet using `toTweet()` method:**

This is a [\#test](https://twitter.com/search?q=%23test) tweet by [@jabranr](https://twitter.com/jabranr) to confirm methods from [\#Fetchwitter](https://twitter.com/search?q=%23Fetchwitter). More at

A [JavaScript version](https://gist.github.com/jabranr/68515719cde0653d641d) is also available.

#### Disclaimer

[](#disclaimer)

I made this library just for learning purpose and have been improving it. A lot of inspiration has come from [Abraham's comprehensive TwitterOAuth](https://github.com/abraham/twitteroauth) library. If you need a complete Twitter API support then please use Abraham's library instead.

#### Issues reporting/tracking

[](#issues-reportingtracking)

[Github Repo Issues](https://github.com/jabranr/fetchwitter/issues)

#### Contribution

[](#contribution)

In order to contribute:

1. Fork the repository
2. Create a new branch
3. Once you are ready then make a pull request

#### License

[](#license)

MIT License -

© [@jabranr](https://twitter.com/jabranr) - 2014-2-15

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~86 days

Total

5

Last Release

3979d ago

### Community

Maintainers

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

---

Top Contributors

[![jabranr](https://avatars.githubusercontent.com/u/2131246?v=4)](https://github.com/jabranr "jabranr (58 commits)")

---

Tags

oauth-authenticationphptwitter-apiphpoauthtwitterTwitter APIfetch-tweets

### Embed Badge

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

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

###  Alternatives

[hwi/oauth-bundle

Support for authenticating users using both OAuth1.0a and OAuth2 in Symfony.

2.4k21.5M68](/packages/hwi-oauth-bundle)[socialconnect/auth

Social Connect Auth Component

568845.4k5](/packages/socialconnect-auth)[artdarek/oauth-4-laravel

OAuth Service Provider for Laravel 4

693504.8k](/packages/artdarek-oauth-4-laravel)[and/oauth

Simple and amazing OAuth library with many providers. Just try it out!

4645.2k2](/packages/and-oauth)[lorenzoferrarajr/lfj-opauth

LfjOpauth is a Zend Framework 2 module that enables support for many authentication providers through the Opauth framework.

2915.4k](/packages/lorenzoferrarajr-lfj-opauth)

PHPackages © 2026

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