maalls/twitterapi

PHP实现的Twitter API。

v1.2.5 2018-03-01 02:05 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:20:38 UTC


README

使用OAuth 1.1的简单Twitter API,用PHP编写。

使用Composer安装

将以下行添加到composer.json的require部分

  "require": {
    "maalls/TwitterApi": "~1.0"
  }

然后运行以下命令行

$composer update

示例

use Maalls\TwitterApi;

// A get request.
$api = new TwitterApi($access_token, $access_token_secret, $consumer_key, $consumer_secret);
$json = $api->get('search/tweets', array('q' => "github"));

// A post request.
$json = $api->>post("statuses/update", array("status" => "I love coding."));

// iterate() works for actions that returns an array of tweets: it collects all the tweets available by making several HTTP request and adjusting max_id parameters.
// see https://dev.twitter.com/rest/public/timelines
$json = $api->iterate('twitter/search', array('q' => 'githun'));

该类还将HTTP响应头收集到一个数组中,这非常有用,因为它包括速率限制信息

var_dump($api->header);

array(17) {
  [...]
  'x-rate-limit-limit' =>
  string(3) "180"
  'x-rate-limit-remaining' =>
  string(3) "179"
  'x-rate-limit-reset' =>
  string(10) "1416472112"
  [...]
}