简体   繁体   中英

How to create Twitter widget?

I want to create the Twitter widget for my web application.

I don't want to use the widgets provided by Twitter because if there are thousands of users then I have to create a separate widget for everyone, which is not possible.

I want to display all the tweets from the timeline of the user which is currently logged in to my web application.

I have to force my web application user to sign in to Twitter before accessing the timeline.

How to do that?

Is there anyone having detail idea about it?

Please help me.

By using this code,You can add your own twitter widget .You can also customize it.

  echo "<ul id='news'>";
  $twit_usr = 'username';//Please enter your twitter username
//$num_tweets = '60';
$reader = new XMLReader();
$reader->open( 'http://api.twitter.com/1/statuses/user_timeline/'.$twit_usr.'.xml/'                              );
while ( $reader->read() ) 
{
   if ( $reader->nodeType == XMLREADER::ELEMENT ) 
   {
      $name = $reader->name;
      if( $name == "status" )
      {
        while( $reader->read() )
        {
            if( $reader->nodeType == XMLREADER::ELEMENT )
            {
                $noName = $reader->name;
                if( $noName == "text" )
                {
                    $reader->read();
                    $checkUrl = $reader->value;
                    $text = preg_replace('/(?<!http:\/\/)(www.[-a-zA-Z0-9@:%_\+.~#?&\/=]+)/i', '<a href="http://\1">\1</a>', $text);
                    $pattern = "#(http:\/\/[^ ]+)#i";
                    $replacement = "<a href=\"$0\" target=\"_blank\">$0</a>";
                    $finalString = preg_replace( $pattern, $replacement, $checkUrl );
                    //$finalString = ereg_replace("[[:space:]]+[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]+[[:alnum:]]+[[:space:]]", "<a href=\"\\0\">\\0</a>", $checkUrl);
                    $result .= '<li>'.$finalString . '</li>';
                    //break;
                }//close if noName match

            }//close if nodeType
        }//close while reader read inner
      }//close if name item  
   }//close if nodeType
}//close while reader-read outer
 print_r($result);
 echo '</ul>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM