PHPackages                             jnicol/tweet-php - 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. jnicol/tweet-php

ActiveLibrary[API Development](/categories/api)

jnicol/tweet-php
================

A PHP class for querying the Twitter API and rendering tweets as an HTML list

0778↓100%PHP

Since May 13Pushed 6y agoCompare

[ Source](https://github.com/sampodina/tweet-php)[ Packagist](https://packagist.org/packages/jnicol/tweet-php)[ RSS](/packages/jnicol-tweet-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

TweetPHP
========

[](#tweetphp)

A PHP class for querying the Twitter API and rendering tweets as an HTML list.

Features
--------

[](#features)

- Works with Twitter API v1.1
- Tweets are cached to avoid exceeding Twitter’s API request rate limits
- A fallback is provided in case the API request fails
- A configuration parameter allows you to specify how many tweets are displayed
- Dates can optionally be displayed in “Twitter style”, e.g. “12 minutes ago”
- You can customize the HTML that wraps your tweets, tweet status and meta information

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

[](#authentication)

To interact with Twitter's API you will need to create a Twitter application at:

After creating your app you will need to take note of following API values: "Consumer key", "Consumer secret", "Access token", "Access token secret"

Usage
-----

[](#usage)

Your API credentials can be passed as options to the class constructor, along with the any other configuration options:

```
$TweetPHP = new TweetPHP(array(
  'consumer_key'        => 'xxxxxxxxxxxxxxxxxxxxx',
  'consumer_secret'     => 'xxxxxxxxxxxxxxxxxxxxx',
  'access_token'        => 'xxxxxxxxxxxxxxxxxxxxx',
  'access_token_secret' => 'xxxxxxxxxxxxxxxxxxxxx',
  'api_params'          => array('screen_name' => 'twitteruser')
));

```

Then you can display the results like so:

```
echo $TweetPHP->get_tweet_list();

```

You can also retreive the raw data received from Twitter:

```
$tweet_array = $TweetPHP->get_tweet_array();

```

Options
-------

[](#options)

Options can be overridden by passing an array of key/value pairs to the class constructor. At a minimum you must set the `consumer_key`, `consumer_secret`, `access_token`, `access_token_secret` options, as shown above.

You should also set an `api_endpoint` and `api_params`, an array of parameters to include with the call to the Twitter API.

Here is a full list of options, and their default values:

```
'consumer_key'          => '',
'consumer_secret'       => '',
'access_token'          => '',
'access_token_secret'   => '',
'api_endpoint'          => 'statuses/user_timeline',
'api_params'            => array(),
'enable_cache'          => true,
'cache_dir'             => dirname(__FILE__) . '/cache/', // Where on the server to save cached tweets
'cachetime'             => 60 * 60, // Seconds to cache feed (1 hour).
'tweets_to_retrieve'    => 25, // Specifies the number of tweets to try and fetch, up to a maximum of 200
'tweets_to_display'     => 10, // Number of tweets to display
'twitter_style_dates'   => false, // Use twitter style dates e.g. 2 hours ago
'twitter_date_text'     => array('seconds', 'minutes', 'about', 'hour', 'ago'),
'date_format'           => '%I:%M %p %b %e%O', // The defult date format e.g. 12:08 PM Jun 12th. See: http://php.net/manual/en/function.strftime.php
'date_lang'             => null, // Language for date e.g. 'fr_FR'. See: http://php.net/manual/en/function.setlocale.php
'twitter_template'      => 'Latest tweets{tweets}',
'tweet_template'        => '{tweet}{date}',
'error_template'        => 'Our twitter feed is unavailable right now. Follow us on Twitter',
'nofollow_links'        => false, // Add rel="nofollow" attribute to links
'debug'                 => false

```

### Deprecated options

[](#deprecated-options)

The following options have been deprecated. You should use `api_params` to set API parameters instead.

```
'twitter_screen_name'   => ''
'ignore_replies'        => true
'ignore_retweets'       => true

```

API endpoints
-------------

[](#api-endpoints)

Since TweetPHP uses Twitter's [Application-only](https://developer.twitter.com/en/docs/basics/authentication/overview/application-only) API authentication model, it can only access certain GET endpoints.

It has been tested with the statuses/user\_timeline endpoint (its default) and the search/tweets endpoint.

Examples
--------

[](#examples)

### Fetch a user's timeline

[](#fetch-a-users-timeline)

```

```

Note that the `api_endpoint` option could be omitted in this case, since 'statuses/user\_timeline' is its default value.

### Search for a hashtag

[](#search-for-a-hashtag)

```

```

Caching
-------

[](#caching)

Caching is employed because Twitter rate limits how many times their feeds can be accessed per hour.

When the user timeline is first loaded, the resultant HTML list is saved as a text file on your web server. The default location for this file is: `cache/twitter.txt`

The raw Twitter response is saved as a serialized array in: `cache/twitter-array.txt`

You can change these file paths using the `cache_dir` option. For example, to set a path from your root public directory try:

```
$_SERVER['DOCUMENT_ROOT'] . '/path/to/my/cache/dir/'

```

Debugging
---------

[](#debugging)

If you are experiencing problems using the script please set the `debug` option to `true`. This will set PHP's error reporting level to `E_ALL`, and will also display a debugging report.

You can also fetch the debugging report as an array or HTML list, even when the `debug` option is set to `false`:

```
echo $TweetPHP->get_debug_list();
$debug_array = $TweetPHP->get_debug_array();

```

Helper methods
--------------

[](#helper-methods)

### autolink

[](#autolink)

Pass raw tweet text to `autolink()` and it will convert all usernames, hashtags and URLs to HTML links.

```
$autolinked_tweet = $TweetPHP->autolink($tweet);

```

This might be handy if you want to process tweets yourself, using the array returned by `get_tweet_array()`.

Credits
-------

[](#credits)

- Feed parsing uses Matt Harris' [tmhOAuth](https://github.com/themattharris/tmhOAuth)
- Hashtag/username parsing uses Mike Cochrane's [twitter-text-php](https://github.com/mikenz/twitter-text-php)
- Other contributors: [Matt Pugh](https://github.com/mattpugh), [Dario Bauer](https://github.com/dariobauer), [Lee Collings](https://github.com/leecollings), [Dom Abbott](https://github.com/domabbott92)

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d30d106e8430ad088626315315f26b432acf70a3661dc9dbac65b338d0aa56a?d=identicon)[samuelpodina](/maintainers/samuelpodina)

---

Top Contributors

[![jnicol](https://avatars.githubusercontent.com/u/1201646?v=4)](https://github.com/jnicol "jnicol (11 commits)")[![sampodina](https://avatars.githubusercontent.com/u/50400830?v=4)](https://github.com/sampodina "sampodina (9 commits)")[![dariobauer](https://avatars.githubusercontent.com/u/454259?v=4)](https://github.com/dariobauer "dariobauer (1 commits)")[![domabbott92](https://avatars.githubusercontent.com/u/18683933?v=4)](https://github.com/domabbott92 "domabbott92 (1 commits)")[![leecollings](https://avatars.githubusercontent.com/u/125487401?v=4)](https://github.com/leecollings "leecollings (1 commits)")[![mattpugh](https://avatars.githubusercontent.com/u/3508270?v=4)](https://github.com/mattpugh "mattpugh (1 commits)")

### Embed Badge

![Health badge](/badges/jnicol-tweet-php/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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