Example code: Using PHP to call Twitter's RSS_PHP tutorial
Jul 21, 2016 pm 02:55 PMThe right sidebar of the "Shouwangxuan" blog originally had a "Miscellaneous Feelings" column, which was used to record short sentences that could not be written in large lengths, or short sentences and remarks that I liked more.
This column was first implemented by calling Fanfou’s API on Weibo. As everyone knows, Fanfou cannot be used. Later, Tencent’s Taotao API was used to implement it. 2010 1 On May 26th, Taotao business will begin to be integrated with QQ Space Mood, so we can only consider giving up. After much thought, I finally considered using Twitter to implement it. However, Twitter is inaccessible in China and cannot be called using js. The server of this blog is overseas. There should be no problem in using PHP to access the Twitter API. Although there is a ready-made WordPress plug-in "Twitter Tools" available, in order to use as few plug-ins as possible, I decided to use PHP directly in the WordPress theme. accomplish. The API interfaces provided by twitter are very rich. After some research, I found that calling the Twitter RSS API is relatively simple and can implement the following functions:
1. Capture the content of twitter RSS. No password is required, only a username.
2. Format the RSS content, display the content and time of the user's own tweets, and exclude the content of @replies' replies to others.
The code is as follows:
01:
02: 03: $username='xjb';/ /change this to your twitter username
04: $feedURL='http://twitter.com/statuses/user_timeline/'.$username.'.rss';
05: $excludePattern='/'.$username.': @/'; //excludes any @repliesexclude @replies content
06: $count=5;// show count
07: $i=0;
08:
09: if(!$xml=simplexml_load_file($feedURL)){
10: trigger_error('Error',E_USER_ERROR);
11: }
12: foreach( $xml->channel->item as $item) {
13: if ( ! preg_match("$excludePattern", $item->title)) {
14: $filteredTitle=htmlspecialchars(" $item->title");
15: $filteredTitle=str_replace("$username: ","",$filteredTitle);
16: //Convert the time zone in China --convert to China Time zone
17: date_default_timezone_set('Asia/Shanghai');
18: $i++;
19:
20: if($i>$count)
21: {
22: break;
23: }
24: ?>
25:
26: (pubDate)); ?>)
27:
28: < ;div align="right">
29: More... div>
30:
Source code download: twitter-rss.rar

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

What are the blockchain data analysis tools?

How To Set Up Visual Studio Code (VS Code) for PHP Development

How do you parse and process HTML/XML in PHP?

Where is the official entrance to DeepSeek? Latest visit guide in 2025

PHP Program to Count Vowels in a String

Bitget Exchange official website login latest entrance

How much is the price of MRI coins? The latest price trend of MRI coin
