TweetPHP: Display tweets on your website using PHP

If you’ve ever wanted to display your latest Twitter tweets on a website, TweetPHP lets you do that using PHP. TweetPHP is a rewrite of my old Twitter RSS feed parser, which stopped working when Twitter phased out their v1 API.


  • 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 twitter feed fails to load
  • Retweets and @replies can be optionally ignored
  • 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


TweetPHP is available on Github


To interact with Twitter’s API you will need to create an API KEY, which you can create at:

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

Those values can be passed as options to the class constructor, along with the Twitter screen name you wish to query:


$TweetPHP = new TweetPHP(array(
  'consumer_key'              => 'xxxxxxxxxxxxxxxxxxxxx',
  'consumer_secret'           => 'xxxxxxxxxxxxxxxxxxxxx',
  'access_token'              => 'xxxxxxxxxxxxxxxxxxxxx',
  'access_token_secret'       => 'xxxxxxxxxxxxxxxxxxxxx',
  'twitter_screen_name'       => 'yourusername'

Then you can display the results like so:

echo $TweetPHP->get_tweet_list();


See TweetPHP’s Github for documentation of all options.


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

You can change this file path by setting the cache_file option. For example, to set a path from your root public directory try:

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


If you are experiencing problems using the plugin 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.

Here are a few tips to help you solve common configuration issues:

tmhOAuth response code: 0

If your debugging report shows the error “tmhOAuth response code: 0”, you can find out more about this error message in the tmhOAuth github README. Dario also offers this solution: “My server didn’t like the the two __DIR__ constants in the tmhOAuth.php file, hard-coded them and it all works now.”

unserialize error

If you receive the PHP warning “[function.unserialize]: Error at offset 0 of 49 bytes”, it might be the case that you have magic quotes enabled in your PHP configuration.


– Feed parsing uses Matt Harris’ tmhOAuth
– Hashtag/username parsing uses Mike Cochrane’s twitter-text-php

94 thoughts on “TweetPHP: Display tweets on your website using PHP

  1. M says:

    I keep getting the following error:
    Fatal error: Call to a member function get_tweet_list() on a non-object in /home/../../TweetPHP.php on line 221

    line 221:
    echo $TweetPHP->get_tweet_list();

  2. Jonathan says:

    @M That error message is telling you that the variable $TweetPHP is not an object. Before line 221 have you created an instance of the TweetPHP class and assigned it to a variable named $TweetPHP?

    e.g. $TweetPHP = new TweetPHP( etc…

  3. Terry Upton says:

    Hi Jonathan,

    I have tried to setup and install this new version but with no joy so far.
    I have taken a similar approach to the original script but I am only getting blank results not even erros.

    I have created the API key and entered the consumer_key, consumer_secret, access_token, access_token_secret and the twitter_screen_name

    I have created the 2 txt documents for the cache with writable permissions and also included the script on the page.


    I have then called get_tweet_list(); ?> within the page.

    But as I say nothing shows, just blank (like an error) but no error reported.

    Any input or insight you can offer please?


  4. Terry Upton says:

    Actually I have sorted it all now. Crisis over.
    Great script Jonathan.

    Thanks again!

  5. Jonathan says:

    @Terry Those are my favourite sort of bugs: the ones that fix themselves! Pleased to hear you got it working.

  6. Terry Upton says:

    Hi Jonathan,

    Seem to have ran into an issue that perhaps you can shed some light on or explain? I ma not sure if it is a bug or my settings….

    So I have two cache files inside the twitter folder and have linked to them in the options section. The cache time is set to 60*60 but the twitter feed isn’t loading the cache instead the error message is displayed (as per the error_message and errror_link_text). The last tweet was from yesterday. Could this be a reate limits issue (although I thought the cache file would stop this) or have I set something up incorrectly?

    Thanks in advance.

  7. nle says:

    @Terry Upton

    How about explaining what you did to sort it out. I also have the same problem. I tried just to replace the previous version of the script, entering all the keys, etc. but I get no output.

  8. Robert says:

    Echoing nle’s comment.

    I have included the script on my page. I have tested to ensure that it is being included OK (by putting some text in the file which duly appears on the page, and doesn’t break the page) but when I try to create a new instance of TweetPHP and then echo it, it breaks the page – the content before the script appears, the Twitter feed and content which should follow the script doesn’t.

    I am assuming that at the end of the script (picking up on your reply to M) I should create a new instance by inserting the code as follows (with the values inserted, of course, as they have been within the class constructor):

    $TweetPHP = new TweetPHP(array(
    ‘consumer_key’ => ”,
    ‘consumer_secret’ => ”,
    ‘access_token’ => ”,
    ‘access_token_secret’ => ”,
    ‘twitter_screen_name’ => ”

    echo $TweetPHP->get_tweet_list();

    But each time I do this I get this effect of the content ‘breaking’.

    Jonathan, I VERY much appreciate your efforts, and folks like you.

  9. Jonathan says:

    @Robert It sounds as if a PHP error is being thrown, but that PHP errors are suppressed, so you are not seeing the error message. If that’s the case, you may be able to enable PHP error reporting by adding the following line before your TweetPHP code:

    Let me know what error message is displayed.

  10. Jonathan says:

    @Terry The simplest way to test that the cache file is being loaded is to manually edit the file (just put some obvious test text in it, something like “testing…”), and see if TweetPHP displays your test text. If not, then it didn’t locate the cache_file, and has fetched the tweets anew.

    I’m thinking that I might need to add a debugging option for TweetPHP that displays information about what is happening behind the scenes, which ought to make it easier to figure out what’s happening in cases like yours.

  11. Jonathan says:

    I have added a new option: debug, which accepts values true|false. When set to true, PHP error reporting will be set to E_ALL, and get_tweet_list will render an HTML list of debugging information. The public methods get_debug_list() and get_debug_array() can also be used to fetch the debugging information.

  12. Robert says:


    I have tried inserting the error reporting instruction before the TweetPHP code but to no avail – still nothing showing after the code is called, and no error being reported. I have also downloaded the new version with the debugging option from Github, set the option to ‘true’, but again to no avail. I do know that the ‘include’ instruction is working as if I insert the word ‘testing’ at the start of the TweetPHP file it shows up on the page. Including the file without calling an instance of TweetPHP doesn’t break the page (as I suppose he constructor isn’t doing anything without further instruction). But when I try to call a new instance of TweetPHP, then the page breaks. It’s obviously something stupid I am doing as others are making the code work.

    So to recap, I am replicating the TweetPHP file, then inserting the various code items from my Twitter application. I have created two blank .txt files and referenced them among the options in TweetPHP. I have included TweetPHP in my page. And then I have tried to create a new instance of TweetPHP, and echo it, at the end of the TweetPHP code.

    One thing I do notice from the TweetPHP code as downloaded, is the following two lines:
    require_once “lib/tmhOAuth/tmhOAuth.php”;
    require_once “lib/twitter-text-php/lib/Twitter/Autolink.php”;

    To my untrained eye it looks as though these addresses are incomplete, if used from my site. Am I supposed to do something with these, or is that taken care of somewhere else in your coding?

    I have managed to get someone else’s PHP Twitter parser working so am not desperate, but I think your program, with all the options laid out, is so much more elegant!

    Again, many thanks for your efforts and attention.

  13. Jonathan says:

    @Robert I think you’re right that the includes are likely causing problems. The relative file paths seem to not be resolving correctly with certain server configurations.

    I have updated TweetPHP so that the method of including files is more robust, and improved the method of determining the path at which to cache files.

    The PHP error reporting level is now set before any includes, so hopefully if the includes are failing then this should now be apparent.

    Can you please download the latest Master from github and try it out.

  14. nle says:

    Hi, first I want to thank you for your work! I really appreciate it, and it is really nice that you keep your script updated when Twitter changes api, etc.

    I got it to show the tweets now, but I have two problems.

    – I find it hard to set an URL from root. I use this in combination with Stacey CMS, and I want to use the default cache directory located under “/app/_cache/”, but the script always thinks it is in whatever folder the php file is.

    – I want to use my local name of the months (norwegian). In previous version I could use “setlocale(LC_ALL, ‘no_NO’);” in the top of the PHP file, but that does not work now – I still get english month names.

    Any solutions to this problem?

  15. Jonathan says:

    @nle You should be able to define a path to the cache directory like so:

    $_SERVER[‘DOCUMENT_ROOT’] . ‘/app/_cache/filename.txt’

    As for the date language, I’m surprised to hear that setlocale used to work for you, since I don’t think it affects PHP’s date() function? In any case, I have modified TweetPHP’s date formatting to use strftime() which respects the locale set using setlocale.

    You can set the locale using the new date_lang option e.g.

    ‘date_lang’ => ‘no_NO’

    If you were previously using a custom date format, you’ll need to rework it for strftime. See:

    Also you can now override the default “Twitter style date” text using the new twitter_date_text option e.g.

    ‘twitter_date_text’ => array(‘seconds’, ‘minutes’, ‘about’, ‘hour’, ‘ago’)

    Let me know if these new language options are behaving the way you expect.

  16. nle says:

    Thank you.

    You know way more than me about PHP, but setting the locale worked for me in the previous version. Why it worked, I don’t know, but I probably did alot of googling/research, and managed to get it to work the last time.

    Anyways, everything seems to work now, except for one weird thing. It looks like the timezone is wrong when I use it in combination with Stacey. I don’t know why, because it works normally when I used it “alone” (pure download from github).

    I fixed the timezone issue by adding “date_default_timezone_set(‘Europe/Oslo’);” in the top of the file.

    Again, thank you for your work and swift response! :)

  17. Jonathan says:

    @nle Thank sofr bringing the time zone thing to my attention. I’ve updated TweetPHP to display dates in the tweeter’s local time (i.e. the same date that is shown on Twitter.)

  18. Neal says:

    TweetPHP is a fantastic! Thank you for your hard work.

    I’ve come across a strange issue: a tweet is missing. I’ve checked the cashed files and reset them several times, but I’m missing a tweet.

    Here is the beta: and here are the original tweets:

    If you look closely, this tweet from July 15 is missing:
    “@KNSeafreight To Open 60,000 sq ft cross dock #warehouse in UK

    No errors are thrown.

    Any ideas why this tweet is overlooked?

  19. Jonathan says:

    @Neal You need to set the ignore_replies option to false. Because that tweet begins with @username, Twitter considers it to be an @reply, and in most cases you don’t want to display those.

  20. Neal says:

    Outstanding! Thank you.

    TweetPHP has saved my bacon. Hmmm, bacon. :)

  21. Jonathan says:

    I’m wondering: would anyone be interested in me extending TweetPHP to make different sorts of queries, such as searching by hashtag? Or an option to display avatars next to tweets?

  22. Anthony says:

    I’m getting this error,what’s up with this one?

    A PHP Error was encountered
    Severity: Notice
    Message: unserialize() [function.unserialize]: Error at offset 0 of 49 bytes
    Filename: tweet-php/TweetPHP.php
    Line Number: 90

  23. DogBear says:

    Hi Jonathan. Struggling to get the feed to come through. Ive changed the text in the txt file and that displayed so it looks as though paths are ok but im not getting the feed through. Ive got 777 permissions set on the cache folder. Error checking turned on shows this:

    Cache expiration timestamp: 1378032149
    Cache file timestamp: 1378031748
    Cache file doesn’t exist or is older than cachetime.
    Fetching fresh tweets using Twitter API.
    tmhOAuth response code: 0
    Bad tmhOAuth response code.
    No tweets were found. error_message will be displayed.

    Any ideas where I might be going wrong? Thanks

  24. Shannon says:

    Is there any chance you might be revisiting TwitterTicker to make it work with Twitter’s API or enabling a ticker or scrolling capibility in TweetPHP? Thank you so much for all your fine work :)

  25. Jonathan says:

    @Anthony If you send me the cache.txt file that PHP is trying to unserialize, I can take a look. By default it’s stored at /cache/twitter.txt. I’m guessing, but one possibility is that PHP is configured with magic quotes turned on? See:

  26. Jonathan says:

    @DogBear See for more on that particular error code. I’ll modify TweetPHP to output the tmhOAuth error message, instead of just the response code. That might assist in debugging.

  27. Jonathan says:

    @Shannon I’m not sure what you mean by “revisiting” TwitterTicker? TwitterTicker isn’t something I’m familiar with at all! I don’t have any plans to add ticker/scroll to TweetPHP – its job is just to pull tweets using the Twitter API, and render them as vanilla HTML. What you choose to do with it after that is up to you, but certainly it would be possible with a sprinkling of CSS and JS to create a ticker of the sort you’re describing.

  28. Shannon says:

    Thank you for your reply – the maker must have built upon your work as you’re included in the ReadMe file. I did figure out the ticker issue and a sprinkle of CSS and JS did do the trick :) Thank you again and keep up the good work!

  29. Jonathan says:

    @Shannon Ah right, they must have been using my old RSS parsing script, which stopped working when Twitter phased out timeline RSS feeds. I’m pleased to hear you got it working.

  30. Yves says:

    Just tried this script. I have consumer key, secret etc.

    The only thing the script does is showing the text from the /cache/twitter.txt. No tweets are loaded/shown/written…

    Any ideas?

  31. DogBear says:

    Hi Johnathan. Problem solved. For anyone having the same problem I’ll explain:

    I needed to update the default paths set for curl_cainfo & curl_capath in tmhOAuth.php with the exact path of the cacert.pem file. E.g. – ‘./tweetphp/lib/tmhOAuth/cacert.pem’

    Thanks for pointing me in the right direction. Good man!

  32. Jonathan says:

    @Yves Turn on TweetPHP’s debugging mode and see what error messages are shown.

  33. Perumal says:

    i have been download the script from [ ] and given the ‘consumer_key’, ‘consumer_secret’,’access_token’,’access_token_secret’,’twitter_screen_name’ information’s correctly but the page didn’t display anything..
    it has display as blank page…

    kindly guide me..


  34. Jonathan says:

    @ Perumal Turn on TweetPHP’s debugging mode and see what error messages are shown.

  35. Perumal says:


    There is no error in my page, there is a blank(empty) page in my website, kindly check the below web link also..

    this is my parked source web directory…

  36. Jonathan says:

    @Perumal Showing me a link to the TweetPHP class file doesn’t help me to help you. Like I said, set TweetPHP’s debug option to true to see what’s going wrong. If you share the debugging output with me then I may be able to assist.

  37. Perumal says:

    Hello Jonathan,

    Thank you for your answer and to spent much more valuable time for me, could you possible to give me the full source code..!
    because i have been tried many times(ways) so kindly give me full execution compressed files..
    that is useful for validate my mistake also…

    please give me full execution files for twitter feeds display on my website..

    Thanks and advance

  38. Zahid Habib says:

    When I run it says “Oops, our twitter feed is unavailable right now”

    Whats wrong?

  39. Jonathan says:

    @Zahid Turn on TweetPHP’s debugging mode and see what error messages are shown.

  40. Alex says:


    Been struggling to get it to work:

    Notice: unserialize() [function.unserialize]: Error at offset 0 of 49 bytes in /home/xxx/domains/ on line 90
    Cache expiration timestamp: 1384468207
    Cache file timestamp: 1384471130
    Cache file is newer than cachetime.
    This is the default twitter.txt cache file.

    Any idea?


  41. Jonathan says:

    @Alex See my reply to Anthony above, about magic quotes.

  42. Alex says:

    Thanks Jonathan!

    I missed that point. Maybe a good idea to put a note at the top, I was miles away from suspecting this, though I am a programmer wannabie :-)


  43. Dario says:

    Hi Jonathan,

    I’m getting a similar error as the error @DogBear got:

    Cache expiration timestamp: 1385338940
    Cache file timestamp: 0
    Cache file doesn’t exist or is older than cachetime.
    Fetching fresh tweets using Twitter API.
    tmhOAuth response code: 0
    Bad tmhOAuth response code.
    No tweets were found. error_message will be displayed.

    I’ve had a look at tmhOAuth but simply can’t figure out what’s gone wrong…

    My Twitter app settings are as follows:
    Access level: Read, write, and direct messages
    Sign in with Twitter: Yes
    Callback URL: None
    @Anywhere: the domain that I’m adding the script to.

    Any idea of what’s up with my setup?


  44. Dario says:

    Please disregard my earlier comment, I figured out what was wrong.

    My server didn’t like the the two __DIR__ constants in the tmhOAuth.php file, hard-coded them and it all works now.

    Thanks for this great little tool.

  45. Jonathan says:

    @Dario That’s a good find. I think I’ll add a Troubleshooting section to this post and include your tip.

  46. Joey says:

    Hi, Thanks for this but i am getting an error saying ” Oops, our twitter feed is unavailable right now. Follow us on Twitter”

    In my file i have a simple code that goes like this;

    $TweetPHP = new TweetPHP();

    //dumb tweet feed here
    echo $TweetPHP->get_tweet_list();”

    What i’m i not doing right?

  47. Jonathan says:

    @Joey Have you enabled TweetPHP’s debug option? What is the debugging output?

  48. Peter says:

    Hi Jonathan,

    I’ve finally taken the time to update the code on our site to work with the new API (again, based on your code) and the one thing I can’t figure out is how to display the display_url instead of url.

    I seem to remember having to strong-arm it into the code with the previous version, but now that it isn’t based on RSS I’m not sure what to do.

    Has anyone else solved this one, or are there a lot of addresses on people’s feeds?

    Thanks and keep up the awesome work!

  49. Hey there, using this on our site, but just getting a message saying “This is the default twitter.txt cache file.”

    Not even getting the twitter_wrap_open variable displaying a Tweets at the beginning or anything.

    See it on MedRevise – I’ve altered the twitter.txt file to say a message “coming soon” whilst I fix it.


  50. Medical dude says:

    No worries, it was the magic quotes thing. Sorted. Thanks.

    What’s an easy way to reset the cache? IE, after making changes?

  51. Bart says:

    Good morning! I’ve been trying to use this plugin, but can’t seem to get it working. The cache .txt files can’t be found, because the path to these files is wrong.

    The path is created as this:
    Warning: fopen(/home/bart747/domains/ [function.fopen]: failed to open stream: No such file or directory in /home/bart747/domains/ on line 153

    The problem is this: portfolio. There’s a dot after portfolio, which is why the path is incorrect. I can’t seem to find out where this dot is coming from though… Any thoughts on where it could come from?

    Thanks in advance!

  52. Bart says:

    magically started working! :) Well, sort of. Getting this error right now:

    Cache expiration timestamp: 1391588499
    Cache file timestamp: 1391522282
    Cache file doesn’t exist or is older than cachetime.
    Fetching fresh tweets using Twitter API.
    tmhOAuth response code: 200
    No tweets were found. error_message will be displayed.

    I’ll try to mess around more :)

  53. Bart says:

    Sorry for spamming this page, but the previous problem has sorta solved itself too. Although i still have this error:

    Cache expiration timestamp: 1391588499
    Cache file timestamp: 1391522282
    Cache file doesn’t exist or is older than cachetime.

    The tweets are not loaded. However, when i delete the cache .txt files the Tweets work fine. There’s a huge error though because it can’t locate the .txt files anymore :(

  54. Marty says:

    Hello. I am trying to get this to work on my website, but when ever I call the TweetPHP function, everything seems to stop working and just not load.
    I am requiring the php file and after that calling the function (passing the options into it) like it says. But cant seem to make it work.
    I have turned on error reporting, but am also not getting any errors displayed.

  55. Al says:

    I have tried for a few hours to get this working. I created a test script
    turning on the debug I only see my twitter.txt cache file.
    I cannot seem to pull the latest tweets down using the script. I have actually tried putting all the options into my test script also with same results.

    my debug output is
    Cache expiration timestamp: 1392319597
    Cache file timestamp: 1392322781
    Cache file is newer than cachetime.
    HI Al This is the default twitter.txt cache file.

  56. Jonathan says:

    @Marty If your page just dies then that’s probably due to a PHP error. Turn on PHP error reporting so you can see the error message. You may need to view the source of the rendered page to see the message.

  57. Jonathan says:

    @Al To figure out why your tweets are not being pulled from Twitter, you should delete the two cache .txt files. The next time the script runs it will try to fetch your timeline from Twitter, and the debug messages might give a clue why that transaction is failing.

    The two most likely reasons are:

    1) You haven’t correctly created your Twitter API key, or populated TweetPHP with those values (see the usage section of this article). I would expect to see a thmOAuth error message in that case.

    2) TweetPHP is able to fetch your timeline from Twitter (it will display them on your site), but is unable to write the tweets to the cache. You’ll know if that’s happening because the cache files will not be recreated after you delete them.

  58. gundam says:

    thx you ^^v
    I’m succeded using this..but share my story first
    * i tried make app (failed). I must enter my phone
    * I type my phone in setting and got charge bout $1 (nah.. not big deal)..
    * I supposed is should respond to twitter accepted my phone but isn’t?!? anyway skip this and i return to the app.. and succed make the app!!
    * in (xx:number), click API Keys
    * generated API Keys (dont forget about permision)
    * API key&API secret goes to consumer_key&consumer_secret
    * access token&secret is same
    * delete cache..

    the problem? I don’t see any. hope everything is fine

  59. Martyn says:

    Can you give me some guidance around the “twitter_date_text” option? I’d quite like it to say for example “3 days ago”. It seems it only does the “X ago” type text if it’s within the one day. Is that right? Can it be changed?

    Not a problem if not, I was just wondering.

  60. Jonathan says:

    @Martyn Yes, the “twitter style dates” will start showing an actual date when a tweet is a day old, which mimics the behaviour on Twitter. If you want to change that you could edit the date parsing logic which starts at line 184. There are currently switch cases for seconds, minutes and hours, and you’d need to change the default case to calculate the number of elapsed days and display that instead of the date.

  61. gundam says:

    I found something related to time. Since the detail are to long.. I posted on my blog. you can check on my blog link

  62. José Luis says:

    Hi Jonathan. I’m using your script, and I’m wondering if it’s possible to automatically ‘refresh’ the tweets or, perhaps, include a button to do the task. Can you point me in the right direction? Thank you!!!

  63. Jonathan says:

    @José If you set the cachetime configuration option to a lower value, like 60 seconds, then the cache will purge and refresh every minute. This requires a page refresh obviously.

  64. gundam says:

    @jose try use cron.. is better than page refresh..
    but remember to ‘log’ every refresh you made on cron..

  65. Mark says:

    Hey man, for me it isn’t working.

    I get this error :

    PHP Notice: unserialize(): Error at offset 0 of 49 bytes in twitter/TweetPHP.php on line 90

  66. Jonathan says:

    @Mark That error message is explained in the post.

  67. How to make it work in WordPress? Thanks!

  68. Hey man,
    I did not actively twitter_style_dates setting are true, but this setting ?

  69. Jonathan says:

    @Atakan I don’t understand your question. The default setting for twitter_style_dates is false. Are you saying that dates are being displayed in Twitter format (e.g. “2 hours ago”) even with twitter_style_dates set to false?

  70. Steve says:

    Hi Jonathan

    This should be a great addition to my website but I just can’t get it working. I’m getting the error:

    Notice: unserialize() [function.unserialize]: Error at offset 0 of 49 bytes in /home/andorr/public_html/myfolder/includes/TweetPHP.php on line 90
    Cache expiration timestamp: 1415914452
    Cache file timestamp: 1415917336
    Cache file is newer than cachetime.

    I checked and magic quotes is turned off.

    Nothing has been written to cache/twitter.txt.

    Any suggestions??

    Many Thanks

  71. Steve says:

    Hi Jonathan

    I posted a query on here yesterday but haven’t heard back – it’s a problem others have had as well, and after returning to the issue today I think it’s because the cache time is defaulted to an hour, so when trying to get it working I couldn’t, but now going back to it today it works perfectly. Whilst getting it working today I set the cache to just 5 seconds so it updated with every amend, but now I’ve put it back to hourly.

    It’s a great script, so thanks for posting it, and maybe this update will help others get it working.



  72. Wafflehampton says:

    Hi guys,

    I don’t know if anyone else is having this issue, but when I require the class file into my main body and then call it, it causes a fatal error saying the class TweetPHP was not found. However if I call the function in the TweetPHP file it works fine. I’ve checked to make sure the script is getting included and it is. Genuinely stumped!

    Also big thanks Jonathon, this script will be perfect when I can get this solved

  73. jawad says:

    i have set keys and token like this

    [edited to remove twitter API credentials]

    i have found this error please help me ….
    Oops, our twitter feed is unavailable right now. Follow us on Twitter

  74. Jonathan says:

    @jawad I copy/pasted the code you provided, and your tweets were successfully displayed. If you are still having problems I recommend setting the debug option to true, and perhaps the debug output will provide you with a clue.

  75. jawad says:

    Debug output provide these results , so please tell me the next step

    Cache expiration timestamp: 1421814020
    Cache file timestamp: 1421628780
    Cache file doesn’t exist or is older than cachetime.
    Fetching fresh tweets using Twitter API.
    tmhOAuth response code: 401
    Bad tmhOAuth response code.
    No tweets were found. error_message will be displayed.

  76. Jonathan says:

    @jawad A Twitter 401 error means your authentication credentials were missing or incorrect. See:

    All I can suggest double check that there are no syntax errors in your access tokens, although as I said I was able to use the credentials you provided in your earlier comment to successfully pull from your Twitter stream.

  77. baibhav says:

    thanks man u saved my day…sexo

  78. Suneeth Shihab says:

    Is there any way to fetch the twitter feeds based on locations?

  79. Jonathan says:

    @Suneeth Yes, but it is not a feature of my TweetPHP class

  80. Fouad R. says:

    I had the same issue as Dario

    tmhOAuth response code: 0
    Bad tmhOAuth response code.
    No tweets were found. error_message will be displayed.

    I solved it by simply updating tmhOAuth from here

    Thanks for this great tool!

  81. Mr Beta says:

    Thanks for the script! I have a quick question: I want to do some more unique css styling of my tweets. Is there a way to break up the {tweet} into more specific things? Like {tweet author} then {tweet text}, etc. That would allow me to style the tweets a little easier.

  82. Jonathan says:

    @Mr Beta I have been slowly making TweetPHP’s templating more flexible, and as a next step I plan to allow access to the full range of data returned by the Twitter API. For now however if the twitter_template and tweet_template options don’t give you enough flexibility you could use the get_tweet_array() method to retrieve the raw array of tweets and do your own parsing & formatting.

  83. Eddy says:

    this is the error i get

    Notice: Use of undefined constant __DIR__ – assumed ‘__DIR__’ in /home/rccghgz/public_html/lib/tmhOAuth/tmhOAuth.php on line 68

  84. Eddy says:

    For those having the __DIR__ error on line 67 and 68. Simply change __DIR__ to dirname(__FILE__) and the error should go away

  85. Patrick says:


    im using TweetPHP for a WebSite project and it’s just working fine but it doesn’t display the dates.

    I’m using the {date} tag to display the dates but it’s not inserting anything.
    Here is my cfg:

    ‘twitter_style_dates’ => false,
    ‘twitter_date_text’ => array(‘seconds’, ‘minutes’, ‘about’, ‘hour’, ‘ago’),
    ‘date_format’ => ‘%I:%M %p %b %e%O’,
    ‘date_lang’ => ‘en_US’,

    Debug is also true. There is no error or anything.
    Thank you for sharing this awesome code and thanks for any help :)

  86. Ash says:

    “I’m wondering: would anyone be interested in me extending TweetPHP to make different sorts of queries, such as searching by hashtag? Or an option to display avatars next to tweets?”

    Yes please :)

  87. Moein says:

    Hi, How to show tweet with utf-8 encoding?

    ex:Persian Tweet or Arabic Tweet

  88. Moein says:

    i Solved :) thanks

  89. Nick says:

    Hello, thanks for this awesome script.

    I am having a problem, it doesn’t matter if I change the username of the person I want to get the tweets from, it only gets the tweets from the user that generated the access tokens.

    Any idea why?

    Thank you very much

  90. Waqas Akbar says:

    how can i get another’s tweet. Like If i want to fetch my brother’s tweets ?

  91. Mhamad says:


    I already posted the tweets on my website using another method, but i want to know if there is any function or script that could refresh my website automatically after tweeting.
    and if there is a way to extract only the tweeted message by itself without the link and image and all that stuff, because I’m trying to develop Twitter based home automation and i need to only execute the tweeted message in my code.

    I really need help and would be very thankfull if anyone can help me

  92. Martin says:

    Hi Jonathan,

    This is working great for me, thank you!

    The one thing I can’t sort at the moment is getting the time to display as “hours ago” even with twitter_style_date set to true. It still displays as 11:53 AM Oct 12th..

    I’ve searched around and can’t see anyone with the same issue (apart from before you had that feature).

    Everything looks okay in the debug, it would be great if you could point me in the right direction for troubleshooting..

    I’m using this in conjunction with bootstrap carousel so I also need to add an ‘active’ class to the first tweet so there isn’t a delay before the first item appears. If there’s an easy way of doing that which I haven’t seen, please let me know.

    Many thanks!


  93. Jonathan says:

    @Martin If the tweet is older than 24 hours then the full date will always be displayed.

  94. Fantastic! Thanks for releasing this. It really expedited adding Tweets to a whole slew of web sites for me. With one auth key and a small bit of tweaks to the code, I am now pulling tweets from all my accounts, consolidating them, and outputting a beautiful display of latest tweets. Much appreciated, and well done!

Comments are closed.