makotokw/twient

PHP 5.3+的Twitter客户端

v0.7 2017-07-20 10:35 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:00:56 UTC


README

php-twient 是一个php5.3+的Twitter客户端库和Composer包。

特性

  • Composer包
  • 使用命名空间(适用于PHP 5.3+)
  • 支持Twitter API v1.1
  • 应与/无php_curl(自动检测php_curl)一起工作

使用方法

使用Composer安装

Composer: https://getcomposer.org.cn/

在项目目录中创建以下composer.json并执行composer install

/path/to/project/composer.json
{
    "require": {
        "makotokw/twient": "dev-master"
    }
}

获取时间线

<?php
use Makotokw\Twient\Twitter;

$consumer_key = 'consumer key for your application';
$consumer_secret = 'consumer secret for your application';
$oauth_token = 'oauth token for your account';
$oauth_token_secret = 'oauth token secret for your account';

$twitter = new Twitter();
$twitter->oAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
$statuses = $twitter->call('statuses/home_timeline');
foreach ($statuses as $status) {
    echo $status['user']['name'].': '.$status['text'].PHP_EOL;
}
?>

发布状态(推文)

$twitter->call('statuses/update', array('status' => 'tweet by php-twient'));

使用闭包与流式API

当回调返回false时,流式方法终止。

$twitter->streaming(
    'statuses/filter',
    array('track' => 'Sushi,Japan'),
    function ($twitter, $status) {
        static $count = 0;
        echo $status['user']['name'] . ':' . $status['text'] . PHP_EOL;
        return ($count++ < 5);
    }
);

替代API

use Makotokw\Twient\Twitter\V1dot1 as Twitter;

$twitter = new Twitter();
...
$twitter->statusesHomeTimeline();       // instead of "call('statuses/home_timeline')"
$twitter->statusesUpdate(...);          // instead of "call('statuses/update', ...)"
$twitter->streamingStatusesFilter(...);    // instead of "streaming('statuses/filter', ...)"

历史版本

v0.7

  • 支持media/upload API

v0.6

  • 添加了供应商命名空间Makotokw\Twient
  • 不再支持TinyURL
  • PSR-4自动加载

v0.5.1

  • 流式API使用https方案

v0.5

  • 支持Twitter API v1.1

v0.4

  • 更新为Composer包
  • 需要PHP5.3+
  • PSR-2编码规范

v0.3.1

  • 当PHP < 5.2.0时,使用Services_JSON代替json_decode

v0.3

  • 修复了OAuth部分在PHP 5.3或更高版本中已弃用的函数
  • 支持趋势方法
  • 更新状态方法和用户方法

v0.2

  • 支持搜索API。
  • 支持REST API的用户、友谊和社会图谱方法。
  • 支持流式API。
  • 调用方法返回关联数组而不是对象。
  • 添加了assoc标志以返回关联数组或对象。

v0.1

  • 首次发布

许可证

MIT许可证(MIT)
也请参阅LICENSE文件