Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How PHP encapsulates Twitter access classes

2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how PHP encapsulates the Twitter access class, which has a certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article.

The details are as follows:

Class Twitter {/ * Method to make twitter api call for the users timeline in XML * * @ access private * @ param $twitter_id, $num_of_tweets * @ return $xml * / private function api_call ($twitter_id, $num_of_tweets) {$c = curl_init (); curl_setopt ($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=$num_of_tweets"); Curl_setopt ($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($c, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt ($c, CURLOPT_TIMEOUT, 5); $response = curl_exec ($c); $response_info = curl_getinfo ($c); curl_close ($c); if (intval ($response_info ['http_code']) = 200) {$xml = new SimpleXMLElement ($response); return $xml;} else {return false } / * Method to add hyperlink html tags to any urls, twitter ids or hashtags in tweet * * @ access private * @ param $text * @ return $text * / private function process_links ($text) {$text = utf8_decode ($text) $text = preg_replace ('@ (https?:// ([-\ w\.] +) + (d +)? (/ ([\ wAccord _\.] * (\?\ S+)) @','$1mm, $text); $text = preg_replace ("# (^ | [\ n]) @ ([^\"\ t\ n\ rapi_call ($twitter_id, $num_of_tweets)) {$result = $cont_o Foreach ($twitter_xml- > status as $key = > $status) {if ($include_replies = = true | substr_count ($status- > text, "@") = = 0 | strpos ($status- > text, "@")! = 0) {$tweet = $this- > process_links ($status- > text); $result. = $tweet_o. $tweet. $tweet_c. $detail_o. Date ('D jS M y strtotime, strtotime ($status- > created_at)) $detail_c;} $result. = $cont_c;} else {$result. = $cont_o. $tweet_o. "Twitter seems to be unavailable at the moment." $tweet_c. $cont_c;} return $result;}} Thank you for reading this article carefully. I hope the article "how to encapsulate Twitter access classes in PHP" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report