[WordPress] 外掛分享: Get Tweets in PHP

WordPress 外掛 Get Tweets in PHP 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「Get Tweets in PHP」是 2015-08-23 上架。
  • 目前有 70 個安裝啟用數。
  • 上一次更新是 2016-12-28,距離現在已有 3049 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 4.0 以上版本才可以安裝。
  • 有 2 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

netgloo | azanelli | aboutnick |

外掛標籤

tweet | tweets | twitter | developers | latest tweets |

內容簡介

這個外掛程式會新增 PHP 類別 GetTweetsInPhp,您可以如下描述使用這個類別從 Twitter 帳戶檢索最新推文 (tweet),隨後能針對您 PHP 程式碼做出不同的方式處理這些推文。

備註:在使用這個外掛程式之前,您應先建立 Twitter 應用程式來源,請參考 http://apps.twitter.com。

功能

從 Twitter 帳戶取得最新 N 則推文。
以 HTML 格式化的方式取得推文內容(包含每個實體的連結)。
支援快取。
設計給開發人員使用。
非常輕量且簡單。
適用於 v1.1 Twitter API。
安裝和解除安裝容易(只需新增/移除外掛程式檔案)。
不會永久地在您的資料庫儲存任何資料(只會暫時快取資料,如果快取被啟用)。
由 Netgloo 團隊自豪製作。

範例使用

從 @netglooweb 取得最新推文的範例程式碼如下:

// 設定組態
$configs = [
// 設定您的 Twitter 應用程式的權杖
'consumer_key' => 'CONSUMER_KEY',
'consumer_secret' => 'CONSUMER_SECRET',

// Twitter 帳戶名稱
'screen_name' => 'netglooweb',

// 推文數量
'count' => 5,
];

// 使用函式 get_tweets 取得最新推文
$tweets = \Netgloo\GetTweetsInPhp::get_tweets($configs);

// ...

// 對於每則推文,顯示 HTML 文字和附加的圖片
foreach ($tweets as $tweet) {

echo "

";
echo $tweet->n_html_text;

if ($tweet->n_has_media_photo) {
echo "";
}

echo "

";

}

// ...

這樣就完成了!祝您玩得愉快!

組態說明

函式 get_tweets() 接受一個組態設定的陣列:

$configs = [

// --- 必填項目 ---

// 您的 Twitter 應用程式權杖
'consumer_key' => '...',
'consumer_secret' => '...',

// Twitter 帳戶名稱
'screen_name' => '...',

// --- 可選項目 ---

// 推文數量
'count' => 20,

// 是否包含轉推 (retweet)
'include_rts' => true,

// 如果是轉推,是否顯示 "Retweeted by ..." 字樣
'show_retweeted_by' => true,

// 是否啟用快取
// 建議在啟用網站時啟用快取,以避免達到 Twitter 的 API 速率限制 (300 次請求 / 15 分鐘)
'cache_enabled' => false,

// 快取過期時間 (以秒為單位)
// 增加值以優化網站速度,減少值以獲得更實時的行為 (但不能少於 4 秒,以免達到速率限制)
'cache_expiration' => 60,

// 範本

// 轉推文字範本
'retweeted_by_template' =>
' Retweeted by {{user_name}}',

// 哈希標籤連結範本
'hashtag_link_template' =>
'' .
'#{{hashtag_text}}
',

// URL 連結範本
'url_link_template' =>
' 'title="{{url_title}}"&

原文外掛簡介

This plugin will add the PHP class 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.
Features

Get latest N tweets from a Twitter account.
Get the tweet’s text formatted as HTML (with links for each entities).
Cache support.
Made for developers.
Really light and simple.
Works with the v1.1 Twitter API.
Trivial install/uninstall (only add/remove the plugin’s files).
No any data will be permanently stored in your database (only transient data
if the cache is enabled).
Proudly coded by Netgloo.

Example usage
Get and show latest tweets from @netglooweb:
// Set configurations
$configs = [
// Set here tokens from your Twitter's app
'consumer_key' => 'CONSUMER_KEY',
'consumer_secret' => 'CONSUMER_SECRET',

// The Twitter account name
'screen_name' => 'netglooweb',

// The number of tweets
'count' => 5,
];

// Get latest tweets using the function get_tweets
$tweets = \Netgloo\GetTweetsInPhp::get_tweets($configs);

// ...

// For each tweet show the HTML text and the attached image
foreach ($tweets as $tweet) {

echo "

";
echo $tweet->n_html_text;

if ($tweet->n_has_media_photo) {
echo "";
}

echo "

";

}

// ...

That’s all! Have fun!
Configurations
The 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.

Other available properties are those returned from the user_timeline Twitter’s API.
These are some useful ones:

created_at
retweet_count
user->name
user->screen_name
user->profile_image_url

If the properties 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

Example
This code use some of the above properties:
// ...

$tweets = \Netgloo\GetTweetsInPhp::get_tweets($configs);

foreach ($tweets as $tweet) {
echo $tweet->created_at . "
";
echo $tweet->n_html_text . "
";
if ($tweet->n_has_media_photo) {
echo $tweet->n_media_photo_url . "
";
}
}

// ...

Limitations
Since we rely on the Twitter’s user_timeline API, you should read the following docs for taking in account any API’s limitation:

https://dev.twitter.com/rest/reference/get/statuses/user_timeline
https://dev.twitter.com/rest/public/timelines

Contributing
For patches, bug reports, suggestions, requests for features there is a Git repository on GitHub here:
https://github.com/netgloo/get-tweets-in-php

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Get Tweets in PHP」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


1.0 | 1.1 | 1.2 | trunk |

延伸相關外掛(你可能也想知道)

  • oAuth Twitter Feed for Developers 》一個符合 Twitter API 1.1 規範的 WordPress 外掛,為主題開發人員提供從 Twitter 使用者時間線取得物件陣列的功能。, 新的 Twitter API 需要您進行 oAuth 認...。
  • Simple Twitter Tweets 》一個簡單的 Twitter 儀表板外掛,使用 Twitter OAth 和 API v1.1,並備份以確保始終顯示您的 Tweets。, 為什麼要使用這個外掛?, 我們的客戶,尤其是共享主機...。
  • Advanced Social Feeds Widget & Shortcode 》Facebook & Twitter Integration 外掛是用來在您的網站上展示您的品牌 Facebook & Twitter 檔案的小工具,以增加您的 Facebook 專頁讚數及 Twitter ...。
  • Customize Feeds for Twitter 》Customize Feeds for Twitter 是一個 WordPress 外掛,可以使用 shortcode 或 widget 在你的網站上即時顯示 Twitter 動態。, 它完全可自定義,可以展示網站風...。
  • TweetScroll Widget 》TweetScroll 是一個使用新的 oAuth API 1.1 顯示您的 Twitter 帳戶最新推文的小工具。, 此簡單的小工具可用於任何網站/部落格。, Twitter 最近關閉了他們的 A...。
  • Tweeple 》對於所有推客,這是適合您的外掛程式。當然,已經有數量繁多的 Twitter WordPress 外掛程式,但 Tweeple 可以給您更 ThemeBlvd 風格的解決方案。, 注意:此外...。
  • Slim Jetpack 》Jetpack 是 Automattic 提供的一個超強的 WordPress 外掛套裝,但使用它需要 WordPress.com 帳戶,即使以前這些模組是獨立的外掛。此外,其行銷橫幅也非常惱...。
  • Display Tweets 》Display Tweets 是一個非常簡單易用的 Twitter feed 外掛,您可以使用 shortcode、PHP 函數或 widget 來顯示您的推文。它完全是面向未來設計,並使用驗證請求...。
  • Wickett Twitter Widget 》在 WordPress 小工具中顯示您的 Twitter 帳戶中的最新推文。使用您網站或主題的 CSS 自訂推文顯示。, 自訂顯示的推文數量。從顯示的推文中過濾 @ 回覆。可選...。
  • Twiget Twitter Widget 》Twiget Twitter Widget 可讓您在任何小工具區域顯示您的最新 Twitter 狀態更新。只需將 Twiget Twitter Widget 加入側邊欄或任何小工具區域,輸入您的 Twitte...。
  • Arrow Custom Feed for Twitter 》首頁 | 演示 | 支援 | 高級版, Twitter Feed by ArrowPlugins 是一款用於 WordPress 的高級 Twitter Feed 外掛程式。您可以透過這個外掛程式將 Twitter Feeds...。
  • Peadig's Twitter Feed: Embedded Timeline WordPress Plugin 》WordPress Twitter Feed 外掛讓您能輕鬆地將任何用戶的推文輸出到 WordPress 頁面、模板或側邊欄!您可以自訂使用者名稱、推文數量,以及輸出的樣式。, , Twi...。
  • Mini twitter feed 》重要通知:Twitter已關閉其v1 API並現在使用v1.1,要更新您的小型Twitter Feed,您需要前往https://twitter.com/settings/widgets/new創建一個新的小工具,並...。
  • Ultimate Twitter Feeds 》Ultimate Twitter Feeds是最好的輕量級外掛之一,可在您的網站上顯示Twitter feeds(推文)。它可以從Twitter個人檔案、Twitter用戶列表和單個推文中提取feed...。
  • FireCask’s Twitter Follow Button 》快速添加 Twitter 追蹤按鈕的外掛。可以輕鬆地實現在您的頁面、文章或佈景主題模板中。, , Twitter Follow Button WordPress 外掛主頁。, 更多的 WordPress ...。

文章
Filter
Apply Filters
Mastodon