wp-pure/twitter-aggregator

一个将多个Twitter账号聚合到单个列表中的Twitter聚合器。包括缓存功能 - 原始目的是与WordPress一起工作 - 但也可以与任何PHP应用程序一起工作。

1.1.0 2019-05-21 06:52 UTC

This package is auto-updated.

Last update: 2024-09-06 12:19:54 UTC


README

此脚本使用twitter-api-php库来检索Twitter推送,聚合它们并缓存。如果包含在WordPress主题或插件中,它将找到WP函数,并将缓存文件夹放入上传文件夹。别再说了,这里有一个示例集成。

Github MIT

通过Composer安装

composer require wp-pure/twitter-aggregator

包含composer的自动加载器

require_once 'vendor/autoload.php';

获取Twitter API密钥

查看下面的URL以创建Twitter应用程序并获取密钥以使用其API。

https://dev.twitter.com/apps/new

代码示例

实例化

// generate an aggregator object
$ta = new twitterAggregator( array(

	// twitter API consumer key, secret, and oath token and oauth secret
    'consumer_key' => "[CONSUMER KEY]",
    'consumer_secret' => "[CONSUMER SECRET]",
    'oauth_access_token' => "[OAUTH ACCESS TOKEN]",
    'oauth_access_token_secret' => "[OAUTH ACCESS TOKEN SECRET]",

    // comma separated list of twitter handles to pull
    'usernames' => "[TWITTER USERNAMES]",

    // set the number of tweets to show
    'count' => 10,

	// set an update interval (minutes)
    'update_interval' => 10,

    // set the cache directory name/path
    'cache_dir' => 'cache',

    // boolean, exclude replies, default true
    'exclude_replies' => true,

    // boolean, include retweets, default true
    'include_rts' => true

) );

方法

实例化聚合器后,有多种使用方式。您可以显示它,带或不带样式,或者检索小部件代码。

// display the widget
$ta->display();

// display the widget without any styles
$ta->display_unstyled();

// fetch the widget code
$code = $ta->widget();

// fetch data
$data = $ta->fetch();

如果您想直接访问API响应数据(不受count选项的限制),请在聚合器对象实例化后使用$ta->data属性。

James Pederson开发。