开发者 |
netgloo
azanelli aboutnick |
---|---|
更新时间 | 2016年12月28日 22:59 |
PHP版本: | 4.0 及以上 |
WordPress版本: | 4.7 |
版权: | GPLv2 or later |
GetTweetsInPhp
. You can use this class as described below for retrieving latest tweets from a Twitter account, then handle the tweets as you want in your PHP code.
Note: you should create a Twitter app before using this plugin. You can do it from here: http://apps.twitter.com.
特点
get_tweets()
function takes an array of configurations:
$configs = [
// --- Required ---
// The tokens from your Twitter's app
'consumer_key' => '...',
'consumer_secret' => '...',
// The Twitter account name
'screen_name' => '...',
// --- Optional ---
// The number of tweets
'count' => 20,
// Include also the retweets
'include_rts' => true,
// In the HTML text will be showed "Retweeted by ..." if the tweet
// is a retweet
'show_retweeted_by' => true,
// Enable the cache
// It is recommended to activate the cache, when you put live
// your website, in order to avoid to reach the Twitter's api rate
// limit of 300 requests / 15-min.
'cache_enabled' => false,
// Cache expiration (in seconds)
// Increase the value to optimize the website's speed, decrease
// the value if you want a more real-time behaviour (but not
// less than 4 seconds to avoid to reach the rate limit).
'cache_expiration' => 60,
// Templates
// Retweeted by text template
'retweeted_by_template' =>
' Retweeted by {{user_name}}',
// Hash tag link template
'hashtag_link_template' =>
'' .
'#{{hashtag_text}}',
// Url link template
'url_link_template' =>
'{{url_text}}',
// User mention link template
'user_mention_link_template' =>
'@{{user_mention_text}}',
// Media link template
'media_link_template' =>
'{{media_text}}'
];
$tweets = \Netgloo\GetTweetsInPhp::get_tweets($configs);
Returned values
The get_tweets()
function will return an Array of tweets. On each tweet object are available these properties:
n_html_text
(String) The tweet text formatted as HTML, with links on each entities.n_is_retweeted
(Boolean) True if the curret tweet is a retweet.n_has_media_photo
(Boolean) True if the current tweet has an attached photo.n_media_photo_url
(String) The url of the tweet's attached photo.n_media_photo_urls
(Array) If the tweet has more than one attached photos this properties contains all the urls.created_at
retweet_count
user->name
user->screen_name
user->profile_image_url
n_is_retweeted
is true the current tweet is a "re-tweet" and the retweeted_status
object is available:
retweeted_status->user->name
retweeted_status->user->screen_name
retweeted_status->retweet_count
user_timeline
API, you should read the following docs for taking in account any API's limitation:
Our custom properties (i.e. properties not from the Twitter's API) are prefixed with an "n". The "n" is the first character in "Netgloo" ;).