Create custom Twitter Widget using PHP

Twitter Embedded timelines are an easy way to display multiple Tweets on your website. You can easily implement Twitter Embedded Timelines into your website from twitter widgets creation section. But some time we need to customize twitter feed as per our project needs. In this tutorial we’ll discuss how to build custom twitter feed using PHP.

We will use TwitterOAuth PHP Library for Authentication with Twitter. Consumer Key (API Key), Consumer Secret (API Secret), Access Token and Access Token Secret are needed for authentication. You should create the Twitter Application first to get these details. If you are need help, you can read our tutorial: How to Create Twitter OAuth Application

TwitterOAuth PHP Library can be found from our downloadable package. Include the TwitterOAuth PHP Library and define some required configuration variables. Using TwitterOAuth PHP Library we will authenticate with Twitter and get the user timeline feeds by Twitter ID. Full code are given below.

just to follow up, images come through ok if you add these two parameters: ‘include_entities’ => true and ‘tweet_mode’ => ‘extended’, and change “$latestTweet = $tweet->text;” to “full_text”.

i’ve realized the images i was referring to are the “summary cards” that twitter transforms the included URL into, with the thumbnail, title, and description from the linked website.

any idea how to create the cards for the link? instead of just altering the URL into an anchor tag?

February 27, 2017 at 3:43 AM

Dave Said...

Hello, great resource here, works well, easy to configure and adapt,
however it doesn’t show images from tweets,
I looked through the data that is returned and I don’t see the image URLs in the ‘twitterData’ object.
Is there a trick to retrieving the tweet images?
thank you.

February 27, 2017 at 12:15 AM

Lukas Said...

Hi! Super script!
One question. How can I add pictures from tweets to this script?