Home Backend Development PHP Tutorial Example code: Using PHP to call Twitter's RSS_PHP tutorial

Example code: Using PHP to call Twitter's RSS_PHP tutorial

Jul 21, 2016 pm 02:55 PM
php rss twitter code use side blog Example Column use of transfer

The 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.

Example code: Using PHP to call Twitters RSS_PHP tutorial

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: &lt ;div align="right">
    29: More... div>
    30:

    Source code download: twitter-rss.rar

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364516.htmlTechArticleThe right sidebar of Shouwangxuan blog originally had a miscellaneous column, which was used to record short things that cannot be written in large lengths. Short sentences, or short sentences and remarks that you like better. This column was originally called...
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot Article Tags

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

    PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

    What are the blockchain data analysis tools? What are the blockchain data analysis tools? Feb 21, 2025 pm 10:24 PM

    What are the blockchain data analysis tools?

    How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

    How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

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

    Where is the official entrance to DeepSeek? Latest visit guide in 2025 Where is the official entrance to DeepSeek? Latest visit guide in 2025 Feb 19, 2025 pm 05:03 PM

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

    PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

    PHP Program to Count Vowels in a String

    Bitget Exchange official website login latest entrance Bitget Exchange official website login latest entrance Feb 18, 2025 pm 02:54 PM

    Bitget Exchange official website login latest entrance

    How much is the price of MRI coins? The latest price trend of MRI coin How much is the price of MRI coins? The latest price trend of MRI coin Mar 03, 2025 pm 11:48 PM

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

    See all articles