0

i want to display twitter tweets in my webpage from twitter using php. anyone have idea help me

thanks in advance.

2
  • 7
    Thats like the new Hello World, huh?
    – Hannes
    Sep 29, 2010 at 13:41
  • 2
    Hello, I have to build this twitter app, can you please do that for me? thanks. -1
    – berkes
    Sep 29, 2010 at 14:46

7 Answers 7

6

Hello please take a look at the twitter API: http://dev.twitter.com/pages/libraries#php

2
  • thanks for reply, there is no solutions for my problem. i want to display twitter tweets in my webpage.
    – raja
    Sep 29, 2010 at 13:49
  • 4
    Actually, if you clicked one of the links in that link I provided, you will come up with a solution. Here's a hint: github.com/abraham/twitteroauth
    – Ruel
    Sep 29, 2010 at 13:52
2

In addition to the libraries listed at the Twitter Developer Pages, you can use Zend_Service_Twitter to work with the Twitter API:

Zend_Service_Twitter provides a client for the » Twitter REST API. Zend_Service_Twitter allows you to query the public timeline. If you provide a username and OAuth details for Twitter, it will allow you to get and update your status, reply to friends, direct message friends, mark tweets as favorite, and much more.

2

If you want a real easy solution, you could even grab the twitter widget: http://twitter.com/goodies/widgets

1

You could learn from Dabr, which is a PHP-frontend written in PHP. It has almost all the features of the Twitter API included.

1
  • Good answer. Thats what I did +1
    – Mob
    Aug 1, 2011 at 9:06
1

This is the best one I've found for basic functionality. It's javascript based, so apparently you're not going to run into issues with the API calls-per-hour limits. And it gives you markup that you can easily modify however you like.

http://twitter.com/widgets/html_widget

Oh, and don't worry about all the people criticizing your question. I didn't read in the guidelines anywhere for this site that you're question has to be significantly advanced to impress everyone. ;-)

1

Ok so I ran into this post and struggled with the answers... but here is my solution... works perfectly... the only issue I see is that is based around retrieving the RSS feed, which Twitter is pretty keen to get rid of - but for a simple solution it works a charm.

function twitter_status(){

$twitter_name = "YOUR_TWITTER_USERNAME";
$myFile = "http://api.twitter.com/1/statuses/user_timeline.rssscreen_name=".$twitter_name;

$dom = new DOMDocument();
$dom -> load($myFile);

$items = $dom->getElementsByTagName('item');

$max_items = 1; // Number of tweets to return.
$count = 0;

foreach ($items as $item) {
    // Select all the elements in the XML document named "Description"
    // The different elements available are Title, Description, pubDate, guid, link and twitter:source
    // You can find this out by opening the link to your twitter rss feed

    $tweets = $item->getElementsByTagName('description');
    $tweet_string = $tweets->item(0)->nodeValue;
    $tweet_string = substr($tweet_string,strpos($tweet_string,":")+2);


    $tweet_date = $item->getElementsByTagName('pubDate');
    $tweet_date = $tweet_date->item(0)->nodeValue;
    $tweet_date = substr($tweet_date,0,16); // Get rid of the excess times at the end of the date

    echo ("<li class='timestamp tweet_".$count."'>Posted ".$tweet_date."</li><li class='tweet tweet_".$count."'>".makelink($tweet_string)."</li>");

    $count = $count+1;
    if ($count>=$max_items){ break; }
    }
}

function makeLink($string){
// Function to convert url to a link

    /*** make sure there is an http:// on all URLs ***/
    $string = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2",$string);

    /*** make all URLs links ***/
    $string = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</A>",$string);

    /*** make all emails hot links ***/
    $string = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<A HREF=\"mailto:$1\">$1</A>",$string);

    return $string;
}

So this is my solution, however it's quite specific to what I wanted - but most of you can work this out hopefully and make necessary adjustments. I'm not a particularly great coder, so if I've made blatant mistakes or could improve this script I would appreciate it.

0

The Twitter API is changing and display requirements are no longer optional. So in addition to requiring the use of Oauth now, you should also be meeting these display standards as they are no longer optional.

There are PHP libraries that help access version 1.1 of the Twitter API, I chose to use CodeBird rather than continue to roll my own going forward. I think the documentation could be a little better though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.