Get Tweets in PHP

Get Tweets in PHP

Wordpress plugin

Install on Wordpress

App Details

This plugin will add the PHP class GetTweetsInPhp. You can use this class as described below for retrieving latest tweets from a Twitter account, then handle the tweets as you want in your PHP code.

Note: you should create a Twitter app before using this plugin. You can do it from here: http://apps.twitter.com.

Features

  • Get latest N tweets from a Twitter account.
  • Get the tweet’s text formatted as HTML (with links for each entities).
  • Cache support.
  • Made for developers.
  • Really light and simple.
  • Works with the v1.1 Twitter API.
  • Trivial install/uninstall (only add/remove the plugin’s files).
  • No any data will be permanently stored in your database (only transient data
    if the cache is enabled).
  • Proudly coded by Netgloo.

Example usage

Get and show latest tweets from @netglooweb:

// Set configurations $configs = [ // Set here tokens from your Twitter's app 'consumer_key' => 'CONSUMER_KEY', 'consumer_secret' => 'CONSUMER_SECRET', // The Twitter account name 'screen_name' => 'netglooweb', // The number of tweets 'count' => 5, ]; // Get latest tweets using the function get_tweets $tweets = \Netgloo\GetTweetsInPhp::get_tweets($configs); // ... // For each tweet show the HTML text and the attached image foreach ($tweets as $tweet) { echo "<p>"; echo $tweet->n_html_text; if ($tweet->n_has_media_photo) { echo "<img src='{$tweet->n_media_photo_url}' width='100%' />"; } echo "</p>"; } // ... 

That’s all! Have fun!

Configurations

The get_tweets() function takes an array of configurations:

$configs = [ // --- Required --- // The tokens from your Twitter's app 'consumer_key' => '...', 'consumer_secret' => '...', // The Twitter account name 'screen_name' => '...', // --- Optional --- // The number of tweets 'count' => 20, // Include also the retweets 'include_rts' => true, // In the HTML text will be showed "Retweeted by ..." if the tweet // is a retweet 'show_retweeted_by' => true, // Enable the cache // It is recommended to activate the cache, when you put live // your website, in order to avoid to reach the Twitter's api rate // limit of 300 requests / 15-min. 'cache_enabled' => false, // Cache expiration (in seconds) // Increase the value to optimize the website's speed, decrease // the value if you want a more real-time behaviour (but not // less than 4 seconds to avoid to reach the rate limit). 'cache_expiration' => 60, // Templates // Retweeted by text template 'retweeted_by_template' => '<em> Retweeted by {{user_name}}</em>', // Hash tag link template 'hashtag_link_template' => '<a href="{{hashtag_link}}" rel="nofollow" target="_blank">' . '#{{hashtag_text}}</a>', // Url link template 'url_link_template' => '<a href="{{url_link}}" rel="nofollow" target="_blank" ' . 'title="{{url_title}}">{{url_text}}</a>', // User mention link template 'user_mention_link_template' => '<a href="{{user_mention_link}}" rel="nofollow" target="_blank" ' . 'title="{{user_mention_title}}">@{{user_mention_text}}</a>', // Media link template 'media_link_template' => '<a href="{{media_link}}" rel="nofollow" target="_blank" ' . 'title="{{media_title}}">{{media_text}}</a>' ]; $tweets = \Netgloo\GetTweetsInPhp::get_tweets($configs); 

Returned values

The get_tweets() function will return an Array of tweets. On each tweet object are available these properties:

  • n_html_text (String) The tweet text formatted as HTML, with links on each entities.
  • n_is_retweeted (Boolean) True if the curret tweet is a retweet.
  • n_has_media_photo (Boolean) True if the current tweet has an attached photo.
  • n_media_photo_url (String) The url of the tweet’s attached photo.
  • n_media_photo_urls (Array) If the tweet has more than one attached photos this properties contains all the urls.

Other available properties are those returned from the user_timeline Twitter’s API.
These are some useful ones:

  • created_at
  • retweet_count
  • user->name
  • user->screen_name
  • user->profile_image_url

If the properties n_is_retweeted is true the current tweet is a “re-tweet” and the retweeted_status object is available:

  • retweeted_status->user->name
  • retweeted_status->user->screen_name
  • retweeted_status->retweet_count

Example

This code use some of the above properties:

// ... $tweets = \Netgloo\GetTweetsInPhp::get_tweets($configs); foreach ($tweets as $tweet) { echo $tweet->created_at . "<br/>"; echo $tweet->n_html_text . "<br/>"; if ($tweet->n_has_media_photo) { echo $tweet->n_media_photo_url . "<br/>"; } } // ... 

Limitations

Since we rely on the Twitter’s user_timeline API, you should read the following docs for taking in account any API’s limitation:

  • https://dev.twitter.com/rest/reference/get/statuses/user_timeline
  • https://dev.twitter.com/rest/public/timelines

Contributing

For patches, bug reports, suggestions, requests for features there is a Git repository on GitHub here:
https://github.com/netgloo/get-tweets-in-php

Pricing

Starting from $0 per month.

Check Out the Social Media & RSS Feeds Widget

By Common Ninja

Social Media & RSS FeedsTry For Free!

App Info

Rating

Reviewers

2 reviews

Tags

developers
latest tweets
tweet
tweets
twitter

Developed By

Netgloo

Quick & Easy

Find the Best Wordpress plugins for you

Common Ninja has a large selection of powerful Wordpress plugins that are easy to use, fully customizable, mobile-friendly and rich with features — so be sure to check them out!

Testimonial

Testimonial plugins for Wordpress

Contact Form

Contact Form plugins for Wordpress

Maps

Maps plugins for Wordpress

Translation

Translation plugins for Wordpress

Chat

Chat plugins for Wordpress

Slider

Slider plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Contact

Contact plugins for Wordpress

Galleries

Galleries plugins for Wordpress

SEO

SEO plugins for Wordpress

Forms

Forms plugins for Wordpress

Comments

Comments plugins for Wordpress

Backup

Backup plugins for Wordpress

Privacy

Privacy plugins for Wordpress

Optimize

Optimize plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Comments

Comments plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Video Player

Video Player plugins for Wordpress

popup

popup plugins for Wordpress

SiteMap

SiteMap plugins for Wordpress

Payment

Payment plugins for Wordpress

Coming Soon

Coming Soon plugins for Wordpress

Inventory

Inventory plugins for Wordpress

Testimonials

Testimonials plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Membership

Membership plugins for Wordpress

Forms

Forms plugins for Wordpress

Analytics

Analytics plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Sliders

Sliders plugins for Wordpress

Analytics

Analytics plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Security

Security plugins for Wordpress

Ads

Ads plugins for Wordpress

Music Player

Music Player plugins for Wordpress

Countdown

Countdown plugins for Wordpress

Email Marketing

Email Marketing plugins for Wordpress

Membership

Membership plugins for Wordpress

Ecommerce

Ecommerce plugins for Wordpress

Customer Support

Customer Support plugins for Wordpress

Video Player

Video Player plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Common Ninja Apps

Some of the best Common Ninja plugins for Wordpress

Browse our extensive collection of compatible plugins, and easily embed them on any website, blog, online store, e-commerce platform, or site builder.

Social Media & RSS Feeds for Wordpress logo

Social Media & RSS Feeds

Add social media and RSS feeds to your site to display fresh content, grow your online presence, and keep visitors engaged with real time updates.

Count-Up Clock for Wordpress logo

Count-Up Clock

Track time since important events with a count up clock that displays elapsed days and hours and keeps visitors engaged.

Animated Headline for Wordpress logo

Animated Headline

Add animated headlines to draw attention to key messages and improve user engagement through visual emphasis.

Social Votes for Wordpress logo

Social Votes

Encourage interaction with social votes that let visitors like, upvote, and rank content, boosting engagement and guiding better decisions.

Job Application Form for Wordpress logo

Job Application Form

Collect candidate information with a job application form that organizes submissions, streamlines hiring, and helps you manage applicants efficiently.

Diagrams for Wordpress logo

Diagrams

Create interactive diagrams with a diagrams widget that lets you build and customize flow charts, improve clarity, and help visitors understand complex ideas easily.

Restaurant Menu Flip Cards for Wordpress logo

Restaurant Menu Flip Cards

Present dishes with restaurant menu flip cards that highlight key details, help visitors explore options easily, and support confident ordering decisions.

Facebook Reviews for Wordpress logo

Facebook Reviews

Show Facebook reviews to build trust, improve credibility, and help visitors make confident purchase decisions that support higher sales.

Highlighted Headlines for Wordpress logo

Highlighted Headlines

Enhance titles with highlighted headlines that use custom colors, animations, and styles to draw attention and help visitors notice key messages.

Card Carousel for Wordpress logo

Card Carousel

Showcase content with a card carousel that combines images and text, improves visual design, and helps visitors explore key information.

Feature Voting for Wordpress logo

Feature Voting

Use feature voting so users submit ideas, vote on requests, and help you prioritize product updates by real customer demand.

Call Button for Wordpress logo

Call Button

Add a call button to your site so visitors can tap to start a phone call instantly, improving direct communication access.

More plugins

plugins You Might Like

Discover Apps By Platform

Discover the best apps for your website

WordPress
Wix
Shopify
Weebly
Webflow
Joomla
PrestaShop
Shift4Shop
WebsiteX5
MODX
Opencart
NopCommerce

Common Ninja Search Engine

The Common Ninja Search Engine platform helps website builders find the best site widgets, apps, plugins, tools, add-ons, and extensions! Compatible with all major website building platforms - big or small - and updated regularly, our Search Engine tool provides you with the business tools your site needs!

Multiple platforms