philbone/twittersearch

Twitter搜索API的包。

dev-master 2018-05-21 18:57 UTC

This package is not auto-updated.

Last update: 2024-09-29 06:14:17 UTC


README

Build Status

Switter是一个Twitter搜索API的包。

索引

  1. 需求
  2. 安装
  3. 如何使用
    1. 示例
  4. 运行测试

需求

  • PHP 7.1或更高版本。
  • Guzzle PHP HTTP客户端。
  • 来自 Twitter应用 的Twitter API密钥

安装

从GitHub克隆仓库

$ git clone https://github.com/philbone/twittersearch.git switter 

在Switter安装的目录中,打开终端并运行 "composer install" 以获取依赖项。

$ composer install

如何使用

  • 导入定义。
  • 从Search类创建一个新的对象。
  • 使用API密钥设置token。
  • 为搜索设置一些值。
  • 搜索值。

示例

use Twitter\Search\Search;

$apiKey = "jLl8hRLXY3xEPHGnx7UndxrcV"; // replace with your own api key.
$apiSecret = "8erBjpOra7GCGkHOK3YbTcqoKTQBSyKgljgG4MCDZi5cKRb7op"; // replace with your own api secret.

$search = new Search();

$search->setToken($apiKey, $apiSecret);

$value = ["q" => "#PHP #Composer"];

$response = $search->search($value);

var_dump($response);

在test/SearchTest.php中可以找到一个详细的测试示例。特别关注示例方法 "testSuccessSearch"。

如何运行Test SearchTest.php

假设PHPUnit作为依赖项已安装,只需从Switter安装的目录打开终端并运行它

$ phpunit